实战案例:Dockerfile 直接制作nginx镜像
在Dockerfile目录下准备编译安装的相关文件
[root@ubuntu1804 ~]#mkdir /data/dockerfile/web/nginx/1.16.1
[root@ubuntu1804 ~]#cd /data/dockerfile/web/nginx/1.16.1
[root@ubuntu1804 1.16.1]#vim nginx.conf
user nginx;
worker_processes 1;
#daemon off;
[root@ubuntu1804 1.16.1]#wget http://nginx.org/download/nginx-1.16.1.tar.gz
编写Dockerfile文件
[root@ubuntu1804 1.16.1]#pwd
/data/dockerfile/web/nginx/1.16.1
[root@ubuntu1804 1.16.1]#vim Dockerfile
[root@ubuntu1804 1.16.1]#cat Dockerfile
#Nginx Dockerfile
FROM centos:centos7.7.1908
MAINTAINER wangxiaochun <root@wangxiaochun.com>
RUN yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel /
&& useradd -r -s /sbin/nologin nginx /
&& yum clean all
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 /
&& rm -rf /usr/local/src/nginx*
ADD nginx.conf /apps/nginx/conf/nginx.conf
COPY index.html /apps/nginx/html/
RUN ln -s /apps/nginx/sbin/nginx /usr/sbin/nginx
EXPOSE 80 443
CMD ["nginx","-g","daemon off;"]
生成nginx镜像
[root@ubuntu1804 ~]#cd /data/dockerfile/web/nginx/1.16.1
[root@ubuntu1804 1.16.1]#vim build.sh
[root@ubuntu1804 1.16.1]#cat build.sh
#!/bin/bash
#
docker build -t nginx-centos7:1.6.1-v2 .
[root@ubuntu1804 1.16.1]#chmod +x build.sh
[root@ubuntu1804 1.16.1]#ls
build.sh Dockerfile index.html nginx-1.16.1.tar.gz nginx.conf
[root@ubuntu1804 1.16.1]#./build.sh
[root@ubuntu1804 1.16.1]#docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx-centos7 1.6.1-v2 1918d29d5f45 17 minutes ago 328MB
nginx-centos7 1.6.1 8c16774437a5 13 hours ago 412MB
centos7-base v1 1ba1317e06dc 15 hours ago 402MB
centos centos7.7.1908 08d05d1d5859 2 months ago 204MB
生成容器测试镜像
[root@ubuntu1804 ~]#docker run -d -p 80:80 nginx-centos7:1.6.1-v2
21c954ad4fb902076832cc9a52dd1502aca43d9bcd2b46a2f164382e4ac7b3f6
[root@ubuntu1804 ~]#docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
21c954ad4fb9 centos7-nginx:1.6.1-v2 "nginx -g 'daemon of…" 6 seconds ago Up 4 seconds 0.0.0.0:80->80/tcp, 443/tcp inspiring_goldwasser
[root@ubuntu1804 ~]#curl 127.0.0.1
Test Page v2 in Docker
[root@ubuntu1804 ~]#docker exec -it 21c954ad4fb9 bash
[root@21c954ad4fb9 /]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.5 0.2 20572 2372 ? Ss 03:30 0:00 nginx: master process nginx -g daemon off;
nginx 6 0.0 0.2 21024 2316 ? S 03:30 0:00 nginx: worker process
root 7 11.5 0.2 11840 2880 pts/0 Ss 03:31 0:00 bash
root 20 0.0 0.3 51764 3376 pts/0 R+ 03:31 0:00 ps aux
[root@21c954ad4fb9 /]# exit
exit
[root@ubuntu1804 ~]#
本文链接:http://www.yunweipai.com/34837.html
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/courses/52664.html