最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

docker volume flag not working for sharing directories? - Stack Overflow

programmeradmin3浏览0评论

According to many documentation, including

/

the -v flag can be used to share directory between host and containers.

I am on Ubuntu 24.04.1 LTS. Docker was installed by the ubuntu installer (server version).


root@uccello:~# docker --version
Docker version 27.2.0, build 3ab4256

root@uccello:~# mkdir /test && echo 'test' > /test/test.txt && cat /test/test.txt
test

root@uccello:~# docker run --rm -it -v /test:/test ubuntu:24.04 /bin/bash

root@f57cbe20aad2:/# ls /test
root@f57cbe20aad2:/#   

root@f57cbe20aad2:/# echo 'container' > /test/container.txt && cat /test/container.txt
container

root@f57cbe20aad2:/# exit
exit

root@uccello:~# ls /test
test.txt
 
root@uccello:~# docker run --rm -it -v /test:/test ubuntu:24.04 /bin/bash

root@7060c375d3c6:/# ls /test
container.txt

You may notice:

  • /test is not shared between the host (uccello) and containers despite using the -v flag
  • the content of /test is permanent between containers (and does not correspond to the content of host /test)

I obtained the same result with other folders.

Some more info:

  • DOCKER_HOST is not set:
root@uccello:/home/localadmin# echo $DOCKER_HOST

  • Here the output of docker info:
Client:
 Version:    27.2.0
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.16.1
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.20.3
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 15
  Running: 1
  Paused: 0
  Stopped: 14
 Images: 3
 Server Version: 27.2.0
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 nvidia runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 472731909fa34bd7bc9c087e4c27943f9835f111
 runc version: 
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.8.0-52-generic
 Operating System: Ubuntu Core 22
 OSType: linux
 Architecture: x86_64
 CPUs: 32
 Total Memory: 125.7GiB
 Name: uccello
 ID: d5479edb-8157-4984-836e-2fe4efedc1a1
 Docker Root Dir: /var/snap/docker/common/var-lib-docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
发布评论

评论列表(0)

  1. 暂无评论