docker学习笔记(五):docker镜像格式_dockerfile格式

本文介绍了如何创建Docker镜像,包括从现有镜像制作、下载模板和使用Dockerfile。详细讲解了Dockerfile的使用,以nginx为例展示了构建过程。此外,还探讨了docker-compose用于批量管理容器的便利性,包括其版本和基本命令,以及如何编写和启动docker-compose.yml文件。
摘要由CSDN通过智能技术生成

1docker 镜像格式:

创建镜像的方法

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值