Container can’t see my files!

Containers are sort of virtual machines, a computer running on a computer. They don’t have access to your actual files, just to what’s available inside their filesystem.

In Windows, you mount a USB drive, a disk, or a network location with a drive letter e.g D,E,F.

In Linux the system doesn’t begin with a letter, it begins with a slash / so you mount it in /mnt or whatever other location you want. Maybe /media, /music, /home/games or /var/lib/pterodactyl

Now, remember what I bolded above? The container only has access to what’s inside its filesystem, so even if you have /music mounted on your machine, the container will not see this directory!

# Nothing inside the container
docker run alpine /bin/sh -c "ls /music"
ls: /music: No such file or directory
# But outside the container, it's there
root@mainframe:~# ls /music

To allow the container to see this directory and access our potato music, we need to mount it!

docker run -v "/music:/music" alpine /bin/sh -c "ls /music"

All we did was add -v "/music:/music", so what does this do?

It mounts the /music folder on your computer inside the /music folder inside the container!

Let’s say you are running a container that really wants its music to be in /home/cool-music-software/tunes and gives you no other option, but your music directory is /music, so what can you do?

# Instead of 
-v "/music:/music"
# We use
-v "/music:/home/cool-music-software/tunes"
# So now we have
docker run -v "/music:/home/cool-music-software/tunes" alpine /bin/sh -c "ls /home/cool-music-software/tunes"
# And if we look in /music
docker run -v "/music:/home/cool-music-software/tunes" alpine /bin/sh -c "ls /music"
ls: /music: No such file or directory

Hopefully this demystifies volumes for you. If you have any trouble leave a comment and I’ll help you out!


Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA ImageChange Image