简体   繁体   中英

Mount host dir into docker container without volume?

Is mounting (--mount or -v) a host directory or host volume into a container only possible if the image defines a volume?

I tried to do

docker run -d -v maven-m2-repo:/root/.m2 maven:3-jdk-8-alpine SOME-MAVEN-PROJECT-RUN

as described in https://github.com/carlossg/docker-maven in order to preserve Maven repository directory between container runs, but nothing gets ever written into my volume or host directory.

The Dockerfile doesn't define any volumes:

docker image inspect 08790c3343de
...
"ContainerConfig": {
  ...
  "Volumes": null,

如果要使用-v创建绑定安装,则需要提供绝对路径-v /path/to/maven-m2-repo:/root/.m2或相对路径-v ./maven-m2-repo:/root/.m2 ,否则-v ./maven-m2-repo:/root/.m2将它们视为卷名。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM