Dockerfile练习2—模拟题

 新建 httpd 目录,然后编写 Dockerfile 文件,要求如下:

1、使用 centos:7 镜像作为基础镜像

2、作者为 xiandian

3、Dockeerfile 要求删除镜像的 yum 源,使当前系统的 local.repo 源文件

4、安装 http 服务

5、暴露 80 端口编写完毕后,构建的镜像名字叫 httpd:v1.0 的镜像 

 

 编写 dockerfile 文件

[root@localhost ~]# mkdir httpd
[root@localhost ~]# cd httpd
[root@localhost httpd]# vi Dockerfile
FROM daocloud.io/centos:7
MAINTAINER xiandian
RUN rm -rf /etc/yum.repos.d/*
ADD centos /opt/centos
ADD local.repo  /etc/yum.repos.d/
RUN yum -y install httpd
EXPOSE 80

 httpd 目录要有 local.repo 里面是 centos 仓库

[root@localhost httpd]# vi local.repo 
[centos]
name=centos
baseurl=file:///opt/centos
gpgcheck=0
enabeld=1

 把 /opt/centos 文件光盘内容复制给 httpd 下的 centos

[root@localhost httpd]# mkdir /opt/centos
[root@localhost httpd]# mount /dev/sr0 /opt/centos/
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost httpd]# cp -r /opt/centos/ .

 构建镜像,依次执行 Dockerfile 文件的脚本代码

[root@localhost httpd]# docker build -f Dockerfile -t httpd:v1.0 .
Sending build context to Docker daemon  4.414GB
Step 1/7 : FROM daocloud.io/centos:7
 ---> 7e6257c9f8d8
Step 2/7 : MAINTAINER xiandian
 ---> Using cache
 ---> 9ac680b40bec
Step 3/7 : RUN rm -rf /etc/yum.repos.d/*
 ---> Using cache
 ---> 0119d6e04d4c
Step 4/7 : ADD centos /opt/centos
  ---> cce065bfc7d0
Step 5/7 : ADD local.repo  /etc/yum.repos.d/
 ---> 6cdae8396238
Step 6/7 : RUN yum -y install httpd
 ---> Running in c69e74366511
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-40.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.6-40.el7.centos for package: httpd-2.4.6-40.el7.centos.x86_64
--> Processing Dependency: system-logos >= 7.92.1-1 for package: httpd-2.4.6-40.el7.centos.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-40.el7.centos.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-40.el7.centos.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-40.el7.centos.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package centos-logos.noarch 0:70.0.6-3.el7.centos will be installed
---> Package httpd-tools.x86_64 0:2.4.6-40.el7.centos will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package            Arch         Version                     Repository    Size
================================================================================
Installing:
 httpd              x86_64       2.4.6-40.el7.centos         centos       2.7 M
Installing for dependencies:
 apr                x86_64       1.4.8-3.el7                 centos       103 k
 apr-util           x86_64       1.5.2-6.el7                 centos        92 k
 centos-logos       noarch       70.0.6-3.el7.centos         centos        21 M
 httpd-tools        x86_64       2.4.6-40.el7.centos         centos        82 k
 mailcap            noarch       2.1.41-2.el7                centos        31 k

Transaction Summary
================================================================================
Install  1 Package (+5 Dependent packages)

Total download size: 24 M
Installed size: 31 M
Downloading packages:
--------------------------------------------------------------------------------
Total                                               55 MB/s |  24 MB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : apr-1.4.8-3.el7.x86_64                                       1/6 
  Installing : apr-util-1.5.2-6.el7.x86_64                                  2/6 
  Installing : httpd-tools-2.4.6-40.el7.centos.x86_64                       3/6 
  Installing : centos-logos-70.0.6-3.el7.centos.noarch                      4/6 
  Installing : mailcap-2.1.41-2.el7.noarch                                  5/6 
  Installing : httpd-2.4.6-40.el7.centos.x86_64                             6/6 
  Verifying  : httpd-2.4.6-40.el7.centos.x86_64                             1/6 
  Verifying  : httpd-tools-2.4.6-40.el7.centos.x86_64                       2/6 
  Verifying  : apr-1.4.8-3.el7.x86_64                                       3/6 
  Verifying  : mailcap-2.1.41-2.el7.noarch                                  4/6 
  Verifying  : apr-util-1.5.2-6.el7.x86_64                                  5/6 
  Verifying  : centos-logos-70.0.6-3.el7.centos.noarch                      6/6 

Installed:
  httpd.x86_64 0:2.4.6-40.el7.centos                                            

Dependency Installed:
  apr.x86_64 0:1.4.8-3.el7                                                      
  apr-util.x86_64 0:1.5.2-6.el7                                                 
  centos-logos.noarch 0:70.0.6-3.el7.centos                                     
  httpd-tools.x86_64 0:2.4.6-40.el7.centos                                      
  mailcap.noarch 0:2.1.41-2.el7                                                 

Complete!
Removing intermediate container c69e74366511
 ---> c9ebeefa2dc5
Step 7/7 : EXPOSE 80
 ---> Running in bf6c77709336
Removing intermediate container bf6c77709336
 ---> a411055499f2
Successfully built a411055499f2
Successfully tagged httpd:v1.0
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值