Docker Community Forums

Share and learn in the Docker community.

Access docker container files?

How to access docker container files? Such as var/www/html

My current setup is

ubuntu 16.04 > docker
- docker container:
- lemp stack with ubuntu base 16.04
with openssh-server installed
with ubuntu-standard package installed

you could mount volumes

docker run -ti -v $(pwd):/mnt ubuntu bash

would mount your current directory into the container as /mnt. Replace it with the paths you need to access your files.

A little more tricky is it, if the container is already stopped and you still want to access the files from it. In this case you could use docker cp container_name:/foo /tmp/foo. This will copy /foo from your container into /tmp/foo from your host.

Hope this helps you a bit.

1 Like

@think thank you for replying, i really appreciate it,

what is $(pwd): ? replace with container id?

afterwards i can access the files through my main ip? the bin/bash

i’m sorry for the noobish question, i am still new to docker.

$(pwd) is the path you are currently in
/home/08ski11s/ for example

Afterwards you can access the files directly by going into the folder you mounted in.

so i’ll replace $(pwd) to my working directory file /webapp

docker run -ti -v /webapp:/mnt ubuntu bash

where can i access /mnt ? to my main ip using ssh? currently installed openssh-server in my main docker based ubuntu server

/webapp should be a folder on your host. So on your ubuntu server.
/mnt is then a folder within your container.

1 Like

how to docker run to a specific container? using the container id?

e.g below:


docker run -ti -v $(pwd):/mnt “container id without the quotes” ubuntu bash




docker run -ti -v $(pwd):/mnt ubuntu bash “container id here without the quotes”


can i use bin/bash to shell the volume?

after i make changes to the file, it will automatically rewrites or make changes to the main container file directory folder?

if your docker host system has a /webapp directory, then you could do

docker run -ti -v /webapp:/mnt ubuntu ls -lisa /mnt

This will print you all files within the host /webapp directory

change to the directory you wish to access within the container

cd /webapp

Start the docker container in an interactive mode

docker run -it -v $(pwd):/mnt bash

This will create a new container from the specified image, and place you at a bash prompt within the container.

Within the container, copy to / from the /mnt directory

cp /mnt/webfile.* /www/html/
cp /var/log/logfile /mnt/logfile

exit the container


list the files in /webapp


They should reflect changes you made while in the container.

I don’t think that there is a way to do this for an already existing container. You could exec a shell within the running container and look at the files / directory structure, or use the docker cp command to copy files in and out of the container. I don’t think the container needs to be running to do this.