用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欢迎页面代码