环境:
[root@linux-node1 ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [root@linux-node1 ~]# uname -a Linux linux-node1 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux [root@linux-node1 ~]#
创建目录并下载对应的软件包:
[root@linux-node1 ~]#mkdir -p nginx_centos [root@linux-node1 ~]# [root@linux-node1 nginx_centos]# ll total 2864 -rw-r--r-- 1 root root 864430 Aug 6 21:12 nginx-1.9.3.tar.gz -rw-r--r-- 1 root root 2058349 Aug 6 21:39 pcre-8.37.tar.gz [root@linux-node1 nginx_centos]#
编写Dockerfile文件:
[root@linux-node1 nginx_centos]# vim Dockerfile #Version 1.0 #Author: Wilson #Base p_w_picpaths FROM centos #MAINTAINER MAINTAINER Wilson #ADD ADD pcre-8.37.tar.gz /usr/local/src ADD nginx-1.9.3.tar.gz /usr/local/src #RUN RUN yum -y install wget gcc gcc-c++ make openssl openssl-devel RUN useradd -s /sbin/nologin -M www #WORKDIR WORKDIR /usr/local/src/nginx-1.9.3 RUN ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-pcre=/usr/local/src/pcre-8.37 && make && make install RUN echo "daemon off;" >>/usr/local/nginx/conf/nginx.conf ENV PATH /usr/local/nginx/sbin:$PATH EXPOSE 80 CMD ["nginx"] [root@linux-node1 nginx_centos]#
创建镜像并查看:
[root@linux-node1 nginx_centos]# docker build -t ningx-file:v01 ./ [root@linux-node1 nginx_centos]# [root@linux-node1 nginx_centos]# docker p_w_picpaths REPOSITORY TAG IMAGE ID CREATED SIZE ningx-file v01 460b5af495c4 16 minutes ago 531.9 MB nginx/ningx 1.9.3v02 097c98e3cb2b About an hour ago 534.6 MB nginx 1.9.3 d2cfb9ed3f2b 6 hours ago 534.6 MB docker.io/centos latest 970633036444 8 days ago 196.7 MB [root@linux-node1 nginx_centos]#
利用创建的镜像启动一个容器webserver002
[root@linux-node1 nginx_centos]#docker run -d -p 9000:80 --name webserver002 460b5af495c4 [root@linux-node1 nginx_centos]# [root@linux-node1 nginx_centos]# docker ps -a|grep webserver002 5ab1e96830c1 460b5af495c4 "nginx" 9 minutes ago Up 9 minutes 0.0.0.0:9000->80/tcp webserver002 [root@linux-node1 nginx_centos]
说明:-p将宿主机本地端口与容器内部端口进行指定映射,这里是宿主机本地9000端口与容器内部80端口映射
验证是否能通过9000端口访问:截图如下:
至此,支持nginx的服务的docker镜像创建完成
转载于:https://blog.51cto.com/ucode/1835312