Docker Community Forums

Share and learn in the Docker community.

How to mount data from container onto host?

So I’m using a docker container to host a garrysmod server. The server has a garrysmod folder that has a bunch of subfolders like addons, cfg, etc. I currently use the -v flag to mount just one subfolder like so -v cfg:garrysmod/cfg/ to get just the config files, but I want to mount the entire garrysmod folder like -v garrysmod:garrysmod/. The problem is I don’t already have all the files that I need, I have some files like in the cfg folder, and the docker container has the rest. Is there a way to mount such that the data I provide overrides inside the container, and the container fills in everything else? Or would the better thing be to just copy the data from the container while its running and use that as the mount volume?

I’m trying my second method where I copied the folder from inside the running container to a folder on my host: garrysmod. I then killed the container and restarted it with the flag -v garrysmod:/garrysmod/ so the containers folder had access to the files on my host. However, when I started the container, I saw a bunch of errors in the logs about trying to write/close a null file handle, so I think my container doesn’t have the permissions to write to the mounted volume? Am I understanding that correctly? If so, how would I fix that?

I figured it out! I ran ls -n on my host to see who owned the folder, and I exec’d into my container and did the same thing to compare the uid:guid. They were different, so I ran chown on my host folder to match the uid:guid of the folder inside the container. Now when I run my container, I no longer get any issues!