1、检查可使用镜像,本地可使用的镜像为centos:6.7
$ sudo docker p_w_picpaths
2、dockerfile编写
Dockerfile如下:
#基础镜像
FROM centos:6.7
#制作者
MAINTAINER author [email protected]
#执行安装依赖库
RUN yum install -y pcre-devel wget net-tools gcc zlib zlib-devel make openssl-devel
#将本地文件上传(也可以url地址wget),如果是压缩文件,自动解压(copy用类似,但copy不会自动解压)
ADD nginx-1.10.3.tar.gz /tmp/
RUN mkdir -p /usr/local/nginx
#切换到工作目录
WORKDIR /tmp/nginx-1.10.3
RUN ./configure --prefix=/usr/local/nginx && make && make install
RUN rm -vf /usr/local/nginx/conf/nginx.conf
#将配置文件上传
COPY nginx.conf_standard /usr/local/nginx/conf/nginx.conf
#设置端口
EXPOSE 80
3、执行build
$ sudo docker build -t centos6.7_nginx .
执行结果如下:
Sending build context to Docker daemon 918.5 kB
Sending build context to Docker daemon
Step 0 : FROM centos:6.7
---> a8b4df3be85c
Step 1 : MAINTAINER chenrx [email protected]
---> Using cache
---> 6feb132a34f1
Step 2 : RUN yum install -y pcre-devel wget net-tools gcc zlib zlib-devel make openssl-devel tar
---> Using cache
---> ec00865b5de9
Step 3 : ADD nginx-1.10.3.tar.gz /tmp/
---> 0a887e372c94
Removing intermediate container 8868de4ba046
Step 4 : RUN mkdir -p /usr/local/nginx
---> Running in 593a2057654c
---> 84a2fba9432a
Removing intermediate container 593a2057654c
Step 5 : WORKDIR /tmp/nginx-1.10.3
---> Running in 3ddab737cf1d
---> 1291031daf91
Removing intermediate container 3ddab737cf1d
Step 6 : RUN ./configure --prefix=/usr/local/nginx && make && make install
.....
.....
Step 7 : RUN rm -vf /usr/local/nginx/conf/nginx.conf
---> Running in 89810f191a32
removed `/usr/local/nginx/conf/nginx.conf'
---> 19ec95b13ecc
Removing intermediate container 89810f191a32
Step 8 : COPY nginx.conf_standard /usr/local/nginx/conf/nginx.conf
---> 5b40524fbeec
Removing intermediate container 223898d290aa
Step 9 : EXPOSE 80
---> Running in 012aba61fb66
---> 6cd7f80a468c
Removing intermediate container 012aba61fb66
Successfully built 6cd7f80a468c
--到此步,安装完成
4、检查安装镜像
$ sudo docker p_w_picpaths
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos6.7_nginx latest 6cd7f80a468c 5 minutes ago 455.8 MB
5、启动程序
$ sudo docker run -itd -P centos6.7_nginx bash
--检查启动情况
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e974a6bfadd9 centos6.7_nginx "bash" 24 seconds ago Up 22 seconds 0.0.0.0:32768->80/tcp distracted_torvalds
--进入新建的容器
$ sudo docker exec -ti e974a6bfadd9 /bin/bash
[root@e974a6bfadd9 nginx-1.10.3]#
--启动nginx
[root@e974a6bfadd9 nginx-1.10.3]#/usr/local/nginx/sbin/nginx
--退出容器(nginx后台运行)
[root@ad145dfcb88d nginx-1.10.3]# exit
6、检查nginx运行
$ curl 127.0.0.1:32768
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.
For online documentation and support please refer to
Commercial support is available at
Thank you for using nginx.