零、 配置 docker 自动补齐
1 安装 bash-completion
yum install bash-completion bash-completion-extras.noarch
2 下载配置文件
curl https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/bash/docker -o /etc/bash_completion.d/docker.sh
3 source 生效
source /etc/bash_completion.d/docker.sh
一、 CentOS7.9 官方镜像
docker pull centos:centos7.9.2009
二、 使用 docker 构建 nginx镜像
2.1 Dockerfile
FROM centos:centos7.9.2009
MAINTAINER zhuang
RUN sed -e 's|^mirrorlist=|#mirrorlist=|g' \ -e 's|^#baseurl=http://mirror.centos.org/centos|baseurl=https://mirror.nju.edu.cn/centos|g' \ -i.bak \ /etc/yum.repos.d/CentOS-*.repo
RUN yum install -y gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib openssl openssl-devel
WORKDIR /usr/local
RUN curl -O https://nginx.org/download/nginx-1.24.0.tar.gz && \ tar -xzvf nginx-1.24.0.tar.gz -C /usr/local && \ mv /usr/local/nginx-1.24.0 /usr/local/nginx-1.24.0-src && \ cd nginx-1.24.0-src && \ ./configure --prefix=/usr/local/nginx-1.24.0 && \ make && make install
EXPOSE 80
CMD ["/usr/local/nginx-1.24.0/sbin/nginx", "-g", "daemon off;"]
|
2.2 build
docker build -t nginx1.24 .
2.3 run
docker run -d -p 80:80 nginx1.24
三、 使用 docker 构建 redis
3.1 Dockerfile
FROM centos:centos7.9.2009
MAINTAINER zhuang
RUN sed -e 's|^mirrorlist=|#mirrorlist=|g' \ -e 's|^#baseurl=http://mirror.centos.org/centos|baseurl=https://mirror.nju.edu.cn/centos|g' \ -i.bak \ /etc/yum.repos.d/CentOS-*.repo
RUN yum -y install cpp binutils glibc glibc-kernheaders glibc-common glibc-devel gcc make gcc-c++ libstdc++-devel tcl
WORKDIR /usr/local
COPY ./redis-7.2.1.tar.gz /usr/local
RUN tar -xzvf redis-7.2.1.tar.gz && \ cd redis-7.2.1 && \ make PREFIX=/usr/local/redis7.2.1 install && \ cp ./redis.conf /usr/local/redis7.2.1/redis.conf
EXPOSE 6379
ENTRYPOINT /usr/local/redis7.2.1/bin/redis-server /usr/local/redis7.2.1/redis.conf
|
3.2 build
docker build -t redis7.2.1 .
3.3 run & verification
docker run -d -p 6379:6379
docker exec -it peaceful_fermi /bin/sh
四、 使用 docker 构建tomcat
4.1 Dockerfile
FROM centos:centos7.9.2009
MAINTAINER zhuang
ADD ./apache-tomcat-8.5.93.tar.gz /usr/local/ ADD ./jdk-8u202-linux-x64.tar.gz /usr/local/
ENV MYPATH /usr/local/ WORKDIR $MYPATH
ENV JAVA_HOME /usr/local/jdk1.8.0_202 ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar ENV CATALINE_HOME /usr/local/apache-tomcat-8.5.93 ENV CATALINE_BASE /usr/local/apache-tomcat-8.5.93 ENV PATH $PATH:$JAVA_HOME/bin:$CATALINE_HOME/lib:$CATALINE_HOME/bin
EXPOSE 8080
CMD /usr/local/apache-tomcat-8.5.93/bin/startup.sh && tail -F /usr/local/apache-tomcat-8.5.93/logs/catalina.out
|
4.2 build
docker build -t tomcat8.5.93 .
4.3 run & verification
docker run -d -p 8080:8080 tomcat8.5.93
五、 常见问题
5.1 docker build 过程 yum install 报错
确保 FROM 的镜像 和 Dockerfile 里 yum 源版本对应起来。