前言:这段时间没有前言了哦拐友们
目录
2.1在 daemon.json 文件中添加私有镜像仓库的地址并重启
2.3多阶段构建(使用FROM命令生成多个镜像,将指定的镜像做为其他镜像的基础镜像环 境来构建)
3.2在 daemon.json 文件中添加私有镜像仓库的地址并重启
未优化前
- mkdir /nginx
-
- FROM centos:7
- RUN yum install -y gcc pcre pcre-devel devel zlib-devel make
- ADD nginx-1.15.9.tar.gz /mnt
- WORKDIR /mnt/nginx-1.15.9
- #关闭debug日志
- RUN sed -i 's/CFLAGS="$CFLAGS -g"/#CFLAGS="$CFLAGS -g"/g' auto/cc/gcc
- RUN ./configure --prefix=/usr/local/nginx
- RUN make
- RUN make install
- EXPOSE 80
- VOLUME ["/usr/local/nginx/html"]
- CMD ["/usr/local/nginx/sbin/nginx","-g","daemon off;"]
减少不必要的缓存(丢到黑洞)删除不必要的缓存文件/磁盘文件
- FROM centos:7
- RUN yum install -y gcc pcre pcre-devel devel zlib-devel make &> /dev/null && yum clean all
- ADD nginx-1.15.9.tar.gz /mnt
- WORKDIR /mnt/nginx-1.15.9
- #关闭debug日志
- RUN sed -i 's/CFLAGS="$CFLAGS -g"/#CFLAGS="$CFLAGS -g"/g' auto/cc/gcc
- RUN ./configure --prefix=/usr/local/nginx &> /dev/null
- RUN make &> /dev/null
- RUN make install &> /dev/null
- RUN rm -rf /mnt/nginx-1.15.9
- EXPOSE 80
- VOLUME ["/usr/local/nginx/html"]
- CMD ["/usr/local/nginx/sbin/nginx""-g","daemon off;"]
-
- docker build -t nginx:v1 .
可以使用&&连接
- FROM centos:7
- ADD nginx-1.15.9.tar.gz /mnt
- WORKDIR /mnt/nginx-1.15.9
- RUN yum install -y gcc pcre pcre-devel devel zlib-devel make &> /dev/null && \
- yum clean all && \
- sed -i 's/CFLAGS="$CFLAGS -g"/#CFLAGS="$CFLAGS -g"/g' auto/cc/gcc && \
- ./configure --prefix=/usr/local/nginx &> /dev/null && \
- make &> /dev/null && make install &> /dev/null &&\
- rm -rf /mnt/nginx-1.15.9
- EXPOSE 80
- VOLUME ["/usr/local/nginx/html"]
- CMD ["/usr/local/nginx/sbin/nginx","-g","daemon off;"]
-
- docker build -f Dockerfile -t nginx:v3 .
- FROM centos:7 as build
- ADD nginx-1.15.9.tar.gz /mnt
- WORKDIR /mnt/nginx-1.15.9
- RUN yum install -y gcc pcre pcre-devel devel zlib-devel make &> /dev/null && \
- yum clean all &&\
- sed -i 's/CFLAGS="$CFLAGS -g"/#CFLAGS="$CFLAGS -g"/g' auto/cc/gcc && \
- ./configure --prefix=/usr/local/nginx &> /dev/null && \
- make &>/dev/null && \
- make install &>/dev/null && \
- rm -rf /mnt/nginx-1.15.9
-
- FROM centos:7
- EXPOSE 80
- VOLUME ["/usr/local/nginx/html"]
- COPY --from=build /usr/local/nginx /usr/local/nginx
- CMD ["/usr/local/nginx/sbin/nginx","-g","daemon off;"]
docker pull registry
- vim /etc/docker/daemon.json
- {
- "insecure-registries": ["192.168.226.60:5000"], #添加此段,“,”不可少,ip是本机IP地址
- "registry-mirrors": ["https://4abdkxlk.mirror.aliyuncs.com"]
- }
-
- systemctl daemon-reload
- systemctl restart docker.service
- docker create -it registry /bin/bash
- docker run -d -p 5000:5000 -v /data/registry:/tmp/registry registry
- '//-p指定端口,一内一外;-v表示挂载,前者是宿主机,后者是容器'
必须先给镜像打标签再上传,不然默认是去公共仓库
- #打标签
- docker tag nginx:latest 192.168.226.60:5000/nginx
- #上传
- docker push 192.168.226.60:5000/nginx
- curl -XGET http://192.168.226.60:5000/v2/_catalog
-
- '//若成功会返回以下值'
- {"repositories":["nginx"]}
- #删除原有镜像
- docker rmi 192.168.226.60:5000/nginx:latest
- #查看镜像
- docker images
- #从本地仓库下载镜像
- docker pull 192.168.226.60:5000/nginx
- #查看镜像
- docker images