docker之镜像制作
#:下载镜像并初始化系统 root@ubuntu:~# docker pull centos #:创建目录 root@ubuntu:/opt# mkdir dockerfile/{web/{nginx,tomcat,jdk,apahce},system/{linux,ubuntu,redhat}} -pv root@ubuntu:/opt# cd dockerfile/web/nginx/ #:编写dockerfile root@ubuntu:/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"] #: 将源码包和配置文件拷贝到本目录 root@ubuntu:/opt/dockerfile/web/nginx# ls Dockerfile nginx-1.16.1.tar.gz nginx.conf #:修改配置文件 root@ubuntu:/opt/dockerfile/web/nginx# vim nginx.conf daemon off; #:制作镜像 root@ubuntu:/opt/dockerfile/web/nginx# docker build -t nginx-1.0:v1 /opt/dockerfile/web/nginx/ #:运行测试 root@ubuntu:/opt/dockerfile/web/nginx# docker run -d -it -p 80:80 nginx-1.0:v1
导出镜像 root@ubuntu:/opt/dockerfile/web/nginx# docker save nginx-1.0:v1 > /usr/local/src/nginx.tar.gz 导入镜像 [root@localhost src]# docker load < nginx.tar.gz