--volume command works when arguments are reversed

Running a mariadb container with system variables configured using a volume doesn’t work when I pass in the configuration file as a volume using the documented arguments

The command that doesn’t work:

docker run --name mariadatabase --env MYSQL_ROOT_PASSWORD= --env MYSQL_ALLOW_EMPTY_PASSWORD=1 --env MYSQL_DATABASE=spp -v */home/king_julien_13/docker/pgdp.cnf:/etc/mysql/conf.d* -p 3306:3306 mariadb:10.5.9

Output:

docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/home/king_julien_13/docker/pgdp.cnf" to rootfs at "/etc/mysql/conf.d": mount /home/king_julien_13/docker/pgdp.cnf:/etc/mysql/conf.d (via /proc/self/fd/7), flags: 0x5000, data: context="system_u:object_r:container_file_t:s0:c154,c963": not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.

But when I run the same command with the -v arguments reversed (container-path:host-path), it works like a charm. This stackoverflow answer is what got me into the working command, but I’m running docker entirely on my host, unlike what is mentioned in the answer

Linux Distro: Fedora 40
Docker Version: Docker version 24.0.5, build %{shortcommit_cli}

Edit-Note:: I tried doing the same thing with podman and the same behaviour happens

What are the stars supposed to be?

Nothing. It was my zsh shell that had those, but they don’t do anything

If these are part of your command they definitely do not do nothing. Are they or did you add them just for highlight in this forum post?

They’re not a part of the command. I’ve ran the commands multiple times even without the asterisk ( i didn’t even notice if before), it’s the same result

Looks like you try to bind a host file into a container folder.

If I am right, this should work: /home/king_julien_13/docker/pgdp.cnf:/etc/mysql/conf.d/pgdp.cnf

Update: yup, it’s the case:

docker run --rm  --entrypoint stat mariadb:10.5.9 /etc/mysql/conf.d
  File: /etc/mysql/conf.d
  Size: 24              Blocks: 0          IO Block: 4096   directory
Device: d1h/209d        Inode: 76877282    Links: 2
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2024-09-18 16:37:27.848104419 +0000
Modify: 2021-04-24 00:32:42.000000000 +0000
Change: 2024-09-18 16:37:27.844104393 +0000
 Birth: -
1 Like

It does work. Do you have any explanation on this one?

It bugs me to think reversing the arguments work but that method also works.

That is already the explanation: you are trying to bind a file into a folder. You can bind a file into a file, or a directory into a directory,. The host source and the container target must be of the same type: either both files, or both directories.

Sorry I didn’t say it correctly. I understood that part.

What I can’t get my head around is how reversing the argument works? I couldn’t find anything relevant on my extensive google search

Because either one of both or both don’t exist, and docker then creates the missing part as right type. I assume if both don’t exist, that docker will bind the fresh created host directory into the created container directory.

1 Like