目录
三、基于上次的mysql的Dockerfile修改做多级构建
一、基于上次的nginx的Dockerfile做多级构建
[root@localhost nginx]#cp Dockerfile{,.bak}
[root@localhost nginx]#ls
Dockerfile Dockerfile.bak html nginx-1.24.0.tar.gz nginx.conf
##修改dockerfile
[root@localhost nginx]#vim Dockerfile
##多级构建nginx镜像
[root@localhost nginx]#docker build -t nginx:lnmp .
[root@localhost nginx]#docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx lnmp 4dca9c42d983 5 seconds ago 208MB
nginx centos cd7bd0d67d77 6 hours ago 560MB
centos 7 eeb6ee3f44bd 2 years ago 204MB
FROM centos:7 as build
#基于centos7镜像
MAINTAINER nginx on centos7 by lxy-20240125
#注释信息
ADD nginx-1.24.0.tar.gz /opt/
#将nginx安装包传输到镜像中
RUN yum -y install pcre-devel zlib-devel gcc gcc-c++ make && \
cd /opt/nginx-1.24.0 && \
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module && \
make && make install
#下载编译安装nginx的依赖环境,以及创建nginx用户,进入nginx目录中,完成配置--编译--安装
ENV PATH=$PATH:/usr/local/nginx/sbin/
#创建镜像的环境变量
ADD nginx.conf /usr/local/nginx/conf/nginx.conf
#将配置文件传输的镜像中,覆盖原有的nginx.conf文件
RUN chmod 777 -R /usr/local/nginx/html/
#修改权限
FROM centos:7
#再次基于centos7
COPY --from=build /usr/local/nginx /usr/local/nginx
#把第一阶段的安装目录复制到第二阶段
RUN useradd -M -s /sbin/nologin nginx
#必须的有个nginx用户
EXPOSE 80
#暴露80端口
CMD ["/usr/local/nginx/sbin/nginx", "-g", "daemon off;"]
#设置启动命令
二、基于上次的php的Dockerfile修改做多级构建
[root@localhost php]#cp Dockerfile{,.bak}
[root@localhost php]#ls
Dockerfile Dockerfile.bak php-7.1.10.tar.bz2 php-fpm.conf php.ini www.conf
[root@localhost php]#vim Dockerfile
[root@localhost php]#docker build -t php:lnmp .
[root@localhost php