#:下载镜像并初始化系统 [email protected]:~# docker pull centos #:创建目录 [email protected]:/opt# mkdir dockerfile/{web/{nginx,tomcat,jdk,apahce},system/{linux,ubuntu,redhat}} -pv [email protected]:/opt# cd dockerfile/web/nginx/ #:编写dockerfile [email protected]:/opt/dockerfile/web/nginx# vim Dockerfile #:第一个字母必须大写,固定格式 FROM centos:latest MAINTAINER XueBin.Ma 316428921@qq.com ENV name nginx RUN yum install vim iotop gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel zlib-devel net-tools libevent libevent-devel systemd-devel -y ADD nginx-1.16.1.tar.gz /usr/local/src RUN cd /usr/local/src/nginx-1.16.1 && ./configure --prefix=/apps/nginx && make && make install RUN mkdir /data/html/nginx -pv && echo 1.txt > /data/html/nginx/index.html && useradd -r -u 66 nginx ADD nginx.conf /apps/nginx/conf/nginx.conf RUN chown -R nginx.nginx /apps/nginx/* && chown -R nginx.nginx /data/html/* RUN ln -sv /apps/nginx/sbin/nginx /usr/bin EXPOSE 80 443 CMD ["nginx"] #: 将源码包和配置文件拷贝到本目录 [email protected]:/opt/dockerfile/web/nginx# ls Dockerfile nginx-1.16.1.tar.gz nginx.conf #:修改配置文件 [email protected]:/opt/dockerfile/web/nginx# vim nginx.conf daemon off; #:制作镜像 [email protected]:/opt/dockerfile/web/nginx# docker build -t nginx-1.0:v1 /opt/dockerfile/web/nginx/ #:运行测试 [email protected]:/opt/dockerfile/web/nginx# docker run -d -it -p 80:80 nginx-1.0:v1
导出镜像 [email protected]:/opt/dockerfile/web/nginx# docker save nginx-1.0:v1 > /usr/local/src/nginx.tar.gz 导入镜像 [[email protected] src]# docker load < nginx.tar.gz
原文地址:https://www.cnblogs.com/maxuebin/p/11512348.html
时间: 2024-10-13 21:20:20