Dockerfile

Dockerfile就是用来构建docker镜像的构建文件!命令脚本!先体验一下!

#创建一个dockerfile文件,名字可以随机,建议dockerfile

就是构建出一个自己的镜像

[root@localhost docker-test-volume]# docker build -f dockerfile1 -t kuangshen/centos .
Sending build context to Docker daemon  2.048kB
Step 1/4 : FROM centos
 ---> 5d0da3dc9764
Step 2/4 : VOLUME ["volume01","volume02"]
 ---> Running in 4425bff9c55e
Removing intermediate container 4425bff9c55e
 ---> f51e48e19840
Step 3/4 : CMD echo "----end----"
 ---> Running in d3302d785cd4
Removing intermediate container d3302d785cd4
 ---> 50eaa5436bec
Step 4/4 : CMD /bin/bash
 ---> Running in 123cb378d465
Removing intermediate container 123cb378d465
 ---> 915412bdf8be
Successfully built 915412bdf8be
Successfully tagged kuangshen/centos:latest
[root@localhost docker-test-volume]# 
[root@localhost docker-test-volume]# 
[root@localhost docker-test-volume]# 
[root@localhost docker-test-volume]# docker images
REPOSITORY         TAG       IMAGE ID       CREATED          SIZE
kuangshen/centos   latest    915412bdf8be   22 seconds ago   231MB
mysql              latest    3218b38490ce   5 weeks ago      516MB
hello-world        latest    feb5d9fea6a5   4 months ago     13.3kB
centos             latest    5d0da3dc9764   4 months ago     231MB
[root@localhost docker-test-volume]# cat dockerfile1
FROM centos

VOLUME ["volume01","volume02"]

CMD echo "----end----"
CMD /bin/bash

 自己创建的数据卷就出来了,但是是匿名挂载,那么我们挂载在什么地方呢?通过docker inspect容器的元数据就可以知道挂载在哪里了。

[root@localhost docker-test-volume]# docker run -it 915412bdf8be /bin/bash
[root@4479c95c06d6 /]# 
[root@4479c95c06d6 /]# 
[root@4479c95c06d6 /]# 
[root@4479c95c06d6 /]# ls
bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var  volume01  volume02
[root@4479c95c06d6 /]# 

上一篇:微服务集成-Dockerfile编译、生成镜像及推送


下一篇:访问图片出现403的解决方法