菜单

波波
发布于 2020-04-22 / 0 阅读
0

【Docker】 编写dockerfile文件

需求

自定义centos7镜像。要求: 1.默认登录路径为 /usr 2.可以使用vim

[root@iZbp18nyz28va2zwadft2qZ ~]# 
[root@iZbp18nyz28va2zwadft2qZ ~]# cd docker-files/
[root@iZbp18nyz28va2zwadft2qZ docker-files]# 
[root@iZbp18nyz28va2zwadft2qZ docker-files]# 
[root@iZbp18nyz28va2zwadft2qZ docker-files]# vim centos_dockerfile

FROM centos:7
MAINTAINER bobo <974619916@qq.com>

RUN yum install -y vim
WORKDIR /usr

cmd /bin/bash
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
~                                                                                                                                       
"centos_dockerfile" [New] 8L, 102C written
[root@iZbp18nyz28va2zwadft2qZ docker-files]# 
[root@iZbp18nyz28va2zwadft2qZ docker-files]# 
[root@iZbp18nyz28va2zwadft2qZ docker-files]# 
[root@iZbp18nyz28va2zwadft2qZ docker-files]# 
[root@iZbp18nyz28va2zwadft2qZ docker-files]# ll
total 4
-rw-r--r-- 1 root root 102 Apr 22 22:28 centos_dockerfile
[root@iZbp18nyz28va2zwadft2qZ docker-files]# 
[root@iZbp18nyz28va2zwadft2qZ docker-files]# 
[root@iZbp18nyz28va2zwadft2qZ docker-files]# docker build -f ./centos_dockerfile -t bobo_centos:1 .
Sending build context to Docker daemon  2.048kB
Step 1/5 : FROM centos:7
 ---> 5e35e350aded
Step 2/5 : MAINTAINER bobo <974619916@qq.com>
 ---> Running in d5c00043a221
Removing intermediate container d5c00043a221
 ---> 842af4e3889a
Step 3/5 : RUN yum install -y vim
 ---> Running in 233181c3e19c
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
 * base: mirrors.163.com
 * extras: mirrors.cn99.com
 * updates: mirrors.163.com
Resolving Dependencies
--> Running transaction check
---> Package vim-enhanced.x86_64 2:7.4.629-6.el7 will be installed
...............................................................................................................省略中间的安装步骤......................................................................................
Complete!
Removing intermediate container 233181c3e19c
 ---> 3dae745934ff
Step 4/5 : WORKDIR /usr
 ---> Running in e442764f0df9
Removing intermediate container e442764f0df9
 ---> cc643b9dcc3c
Step 5/5 : cmd /bin/bash
 ---> Running in c0bbf05b88dc
Removing intermediate container c0bbf05b88dc
 ---> 22df9878af37
Successfully built 22df9878af37
Successfully tagged bobo_centos:1
[root@iZbp18nyz28va2zwadft2qZ docker-files]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE
bobo_centos         1                   22df9878af37        About a minute ago   371MB
bobo_tomcat         1.0                 77cc0392ea49        31 minutes ago       529MB
mysql               5.7                 273c7fcf9499        4 days ago           455MB
nginx               latest              e791337790a6        5 days ago           127MB
tomcat              latest              31a47677561a        5 days ago           529MB
redis               5.0                 975fe4b9f798        5 days ago           98.3MB
centos              latest              470671670cac        3 months ago         237MB
zookeeper           latest              c91a7d13d4d9        5 months ago         224MB
centos              7                   5e35e350aded        5 months ago         203MB
logstash            5.6.15              4b1eb31737d4        13 months ago        660MB
elasticsearch       5.6.11              362c5cb1669b        19 months ago        486MB
kibana              5.6.11              388661dcd03e        19 months ago        390MB
[root@iZbp18nyz28va2zwadft2qZ docker-files]# docker run -it --name=c2 bobo_centos:1
[root@caf5f95e4fa3 usr]# 
[root@caf5f95e4fa3 usr]# cd  
[root@caf5f95e4fa3 ~]# 
[root@caf5f95e4fa3 ~]# 
[root@caf5f95e4fa3 ~]# 
[root@caf5f95e4fa3 ~]# ll
total 4
-rw------- 1 root root 3416 Oct  1  2019 anaconda-ks.cfg
[root@caf5f95e4fa3 ~]# 
[root@caf5f95e4fa3 ~]# vim anaconda-ks.cfg 
[root@caf5f95e4fa3 ~]# 
[root@caf5f95e4fa3 ~]# 
[root@caf5f95e4fa3 ~]# 
[root@caf5f95e4fa3 ~]# 
[root@caf5f95e4fa3 ~]#