环境
Docker version 20.10.7, build f0df350 CentOS 7
背景
根据dockerfile创建镜像
dockerfile
FROM centos
VOLUME ["volume01","volume02"]
CMD echo "----end----"
CMD /bin/bash
构建命令
docker build -f /home/dockerfile -t dcyong/centos:1.0 .
docker run -it dcyong/centos:1.0
问题:
docker: Error response from daemon: OCI runtime create failed: invalid mount {Destination:volume01 Type:bind Source:/var/lib/docker/volumes/51792fcdac1428a98575b423b379b72015ffe47eee9a0f0faebdaee1fd194447/_data Options:[rbind]}: mount destination volume01 not absolute: unknown.
参考 建议docker版本降级。我选择维持现版本。
解决思路
1、官网,没有示例 2、根据官网提示,指定具体的volume01,volume02
VOLUME /home/volume01 /home/volume02
3、新的dockerfile
FROM centos
VOLUME /home/volume01 /home/volume02
CMD echo "-------end---------"
CMD /bin/bash
4、构建
docker rmi -f dcyong/centos:1.0
docker build -f /home/dockerfile -t dcyong/centos:1.0 .
[root@localhost home]
REPOSITORY TAG IMAGE ID CREATED SIZE
dcyong/centos 1.0 27a6ab4bd334 4 seconds ago 209MB
5、启动
[root@localhost home]
[root@5345c487a4cd /]
6、查看
[root@5345c487a4cd /]
volume01 volume02
[root@localhost ~]
"Mounts": [
{
"Type": "volume",
"Name": "cf3f2aff7e50442c23dcca1ab569f62ca1cc86e9292a03899b51cea84d1af86f",
"Source": "/var/lib/docker/volumes/cf3f2aff7e50442c23dcca1ab569f62ca1cc86e9292a03899b51cea84d1af86f/_data",
"Destination": "/home/volume01",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
},
{
"Type": "volume",
"Name": "12ef30dce3b144b9f4b7764c33001797a4d4bc2468ed73b8fdb9eade8a889c94",
"Source": "/var/lib/docker/volumes/12ef30dce3b144b9f4b7764c33001797a4d4bc2468ed73b8fdb9eade8a889c94/_data",
"Destination": "/home/volume02",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
]
7、测试成功
[root@6ba8fd8d8536 /]
volume01 volume02
[root@6ba8fd8d8536 /]
[root@6ba8fd8d8536 volume01]
[root@6ba8fd8d8536 volume01]
test.txt
[root@localhost ~]
[root@localhost _data]
[root@localhost _data]
test.txt
参考
https://docs.docker.com/engine/reference/builder/
|