1、docker 镜像格式:
创建镜像的方法:
1)、可以通过现有的镜像做成容器, 然后在容器里做一些操作后,然后在导出成镜像;
2)、去openvz的官网去下载一个模板;
3)、通过dockerfile 来创建镜像;
dockerfile使用;nginx的镜像;
在当前目录新建 Dockerfile文件,文件内容如下,随后执行;
[root@localhost_001 ~]# cat Dockerfile
## Set the base image to CentOS
FROM centos
# File Author / Maintainer
MAINTAINER yuanhh yuanhh@linux.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
# Set the default command to execute when creating a new container
ENTRYPOINT /usr/local/nginx/sbin/nginx && tail -f /etc/passwd
#tail -f 表示参数表示这个容器一直执行,一直不退出;
执行: docker build -t centos_nginx .
先执行下容器是否可以上网,因为需要包需要联网;
[root@localhost_001 ~]# docker run -itd centos
4a1bc3528bd3d780b2d0595f0c51ebcde805c5534e3c8121dd0174885e9e8cbd
[root@localhost_001 ~]# docker exec -it 4a1bc3 bash
[root@4a1bc3528bd3 /]# ping www.baidu.com
PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=1 ttl=127 time=7.77 ms
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 7.777/7.777/7.777/0.000 ms
[root@4a1bc3528bd3 /]# exit
exit
开始执行;
[root@localhost_001 ~]# docker build -t centos6_nginx .
Sending build context to Docker daemon 571.8MB
Step 1/11 : FROM centos #第一步
---> afa1f6db949f
Step 2/11 : MAINTAINER yuanhh yuanhh@linux.com #第二步
---> Using cache
---> aa3feac756d0
Step 3/11 : RUN yum install -y pcre-devel wget net-tools gcc zlib zlib-devel make openssl-devel
---> Running in 723f96c