Why can’t I see my Docker bind-mounted files on the host?

0
5
Asked By TechWiz123 On

Hey everyone! I'm a total newbie to Docker, coming from a traditional Windows sysadmin background. I've been getting used to CLI and Unix-like systems, but it's definitely a bit of a challenge. I'm trying to set up EJBCA with a persistent database following this guide: https://docs.keyfactor.com/ejbca/latest/tutorial-start-out-with-ejbca-docker-container.

After some tinkering with undocumented settings, I managed to get it working with my own DB username and password. However, there's something strange going on with the bind mount for my database folder. While I can see and list files inside the container, none are showing up on the host file system where I've mounted the folder. I verified that the running user in the container is root. What's even weirder is that I created a file inside the container using the command `sudo docker exec -it ejbca-database touch /var/lib/mysql/myself`, and it persists even after I stop and start the container.

I also tried creating a file directly on the host in the bind mount folder, but it doesn't appear in the container. I'm really confused about what's happening here!

3 Answers

Answered By DevGuru99 On

It sounds like you might be binding to a file rather than a directory. Make sure your volume definition in the compose file ends with a slash `/`, like this: `- ./pkidb/:/var/lib/mysql:rw`. That way, Docker knows you're binding to a directory, which should help with the visibility of files across the host and container.

Answered By DockerDude77 On

Using `sudo` might be part of the issue here. When you use it to run the container, the files might be created in the root user’s directory instead. You could try navigating with a find command, like `find / -name 'myself'`. After a bit, it might show you where the file really ended up. But it sounds like switching to a volume could solve your persistence problem too. Just curious why your data is still around after stopping the container!

Answered By CodeNinja58 On

Did you try running `docker inspect`? It can help you verify how the bind mount is set up. You should see something like this in the output: "Binds": ["/compose/ejbca-ce/pkidb:/var/lib/mysql:rw"]. Double-check that your path is correct.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.