volumes in docker compose can't see files if mounted from outside home directory

Dear all,
I use docker quite a lot but this is the first time I see problem like follows:
System: Ubuntu server.
SELinux: disabled
Docker: 20.10.24, build 297e128 (installed with system)

version: ‘1’
image: busybox
- /data/testdir:/testdir:z
command: tail -F anything

In above example no data stored in /data/testdir is visible inside running container. After copying data to /home/user and changing compose.yaml to

version: ‘1’
image: busybox
- /home/user/testdir:/testdir:z
command: tail -F anything

data becomes visible. Permissions are still the same. Docker-compose runned as root. Data permissons 777. What is going on?

Please remove the :z at the end of your volume bind and try again.

No changes. The compose.yaml I provided here is simplified file for test purpose. In reality I need to share local dir between containers (that’s the reason for :z at the end). But no matter if it’s there or not - still it only works when dealing with dirs within my home dir. If the data is located in root file system - it doesn’t.

Though, you do know those are only relevant with selinux, right?

Please share the output of following commands:

docker info
docker version
dpkg -l | grep docker
snap list docker

Well… No. I didn’t knew that. Good to know.

> docker info
 Context:    default
 Debug Mode: false
  buildx: Docker Buildx (Docker Inc., v0.10.4)
  compose: Docker Compose (Docker Inc., v2.17.2)

 Containers: 3
  Running: 3
  Paused: 0
  Stopped: 0
 Images: 6
 Server Version: 20.10.24
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 2806fc1057397dbaeefbea0e4e17bddfbd388f38
 runc version:
 init version: de40ad0
 Security Options:
   Profile: default
 Kernel Version: 5.15.0-88-generic
 Operating System: Ubuntu Core 22
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 7.538GiB
 Name: donpedro
 Docker Root Dir: /var/snap/docker/common/var-lib-docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Experimental: false
 Insecure Registries:
 Live Restore Enabled: false
> docker version
 Version:           20.10.24
 API version:       1.41
 Go version:        go1.20.7
 Git commit:        297e128
 Built:             Wed Aug 23 20:54:23 2023
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

  Version:          20.10.24
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.20.7
  Git commit:       5d6db84
  Built:            Wed Aug 23 20:55:00 2023
  OS/Arch:          linux/amd64
  Experimental:     false
  Version:          v1.6.20
  GitCommit:        2806fc1057397dbaeefbea0e4e17bddfbd388f38
  Version:          1.1.5
  Version:          0.19.0
  GitCommit:        de40ad0
> dpkg -l | grep docker
-- empty --
> snap list docker
Name    Version   Rev   Tracking       Publisher   Notes
docker  20.10.24  2904  latest/stable  canonical✓  -

Please, format your post according to the following guide: How to format your forum posts
In short: please, use </> button to share codes, terminal outputs, error messages or anything that can contain special characters which would be interpreted by the MarkDown filter. Use the preview feature to make sure your text is formatted as you would expect it and check your post after you have sent it so you can still fix it.

Example code block:

echo "I am a code."
echo "An athletic one, and I wanna run."

Regarding your issue, as @meyay suspected, you installed Docker from snap which is in our opinion is a bad idea. Install it as it is described in the official documentation.

Snap runs packages in a container which is really bad for Docker. I whish I could make canonical stop publishing that snap package.

1 Like

I’m so with you! That makes it so hard for newbes to find what is going on.
Thanks for your help!