Low Orbit Flux Logo 2 D

Docker How To Access File System

It can be important to be able to access the file system of a Docker container. You might want to do this for different reasons including testing, debugging, or just data sharing in production.

Method1 - Get a Shell

If you just want to be able to quickly access the file system on a Docker container you can use the following to get a shell. This will allow you to explore the FS and poke around all you want.


docker exec -ti my-container1 /bin/bash

If you don’t want to connect directly to your container you could also create a snapshot, run it with a shell, and connect to that like this:


docker commit 12345678904b5 snapshot1
docker run -t -i snapshot1 /bin/bash

Method 2 - Quick Copy

You can copy files directly off of a container to your local host like this:


sudo docker cp my-container1:/data1/output.csv /home/user1/mydir

Method 3 - Use a Volume

You can run a container with a local directory bind mounted inside:


docker run -d --name my-container1 -v /src/data:/data ubuntu 

You can also do this in read only mode:


docker run -d --name my-container1 -v /src/data:/data:ro ubuntu

Alternative Methods to access a Container’s File System

You could also runan ssh daemon and use SCP to transfer files between the container and other hosts.

Launch sshd on the container like this ( exposed on port 12345 ):


docker run -d -p 12345:22 my-container1 /usr/sbin/sshd -D

Use scp to copy data off like this:


scp -P 12345 user1@127.0.0.1:/data/output.txt /home/user1/output.txt

You could also just ssh right in like this:


ssh -p 12345 user1@127.0.0.1

Another option would be to set up a samba share on your container. While this is an option you might just be better off using a volume.

Check out our guide here: Samba Setup.