Dockerfile示例(安装nginx)

用dockerfile做一个nginx的镜像:

[root@localhost ~]# vim Dockerfile
## Set the base image to CentOS
FROM centos                                                                        //基于哪个镜像
# File Author / Maintainer
MAINTAINER zhangfei pink0520@foxmail.com
# Install necessary tools
RUN yum install -y pcre-devel wget net-tools gcc zlib zlib-devel make openssl-devel                //下载一些依赖包
# Install Nginx
ADD http://nginx.org/download/nginx-1.8.0.tar.gz .
RUN tar zxvf nginx-1.8.0.tar.gz
RUN mkdir -p /usr/local/nginx
RUN cd nginx-1.8.0 && ./configure --prefix=/usr/local/nginx && make && make install
RUN rm -fv /usr/local/nginx/conf/nginx.conf
ADD http://www.apelearn.com/study_v2/.nginx_conf /usr/local/nginx/conf/nginx.conf
# Expose ports
EXPOSE 80                                                                                                            //暴露80端口
# Set the default command to execute when creating a new container
ENTRYPOINT /usr/local/nginx/sbin/nginx && tail -f /etc/passwd        //可能是bug,执行完之后容器就停止了,所以执行taill一直跑着
[root@localhost ~]# docker build -t centos_nginx .            //-t是指定新镜像的名字

报错!!!

重启一下docker

[root@localhost ~]# docker build -t centos_nginx .
[root@localhost ~]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
centos_nginx                  latest              1ca7222ea640        3 minutes ago       371MB
centos_with_nginx             latest              e2305f4f810d        17 hours ago        438MB
192.168.137.20:5000/ubuntu    latest              93fd78260bd1        19 hours ago        86.2MB
ubuntu                        latest              93fd78260bd1        19 hours ago        86.2MB
192.168.137.20:5000/centos7   latest              b4ef66181d50        21 hours ago        435MB
centos7                       latest              b4ef66181d50        21 hours ago        435MB
centos_with_net               latest              0c8be28a8e72        21 hours ago        300MB
centos                        latest              75835a67d134        5 weeks ago         200MB
registry                      latest              2e2f252f3c88        2 months ago        33.3MB
[root@localhost ~]# docker run -itd -p 81:80 centos_nginx bash
0d60a0369cf0c7f2a2a378b32d35fcd485da55b72e9682a1f46dc280137a429b
[root@localhost ~]# docker exec -it 0d60a0369cf0c7f2 bash
[root@0d60a0369cf0 /]# ps aux |grep nginx                        //可以看容器启动之后nginx也会自动启动
root          1  0.0  0.0  11684  1352 pts/0    Ss+  16:37   0:00 /bin/sh -c /usr/local/nginx/sbin/nginx && tail -f /etc/passwd bash
root          8  0.0  0.0  24884   788 ?        Ss   16:37   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody        9  0.0  0.1  27328  3356 ?        S    16:37   0:00 nginx: worker process
nobody       10  0.0  0.1  27328  3356 ?        S    16:37   0:00 nginx: worker process
root         26  0.0  0.0   9092   664 pts/1    S+   16:37   0:00 grep --color=auto nginx
[root@localhost ~]# curl 127.0.0.1:81            //有nginx欢迎页面代码
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值