How do I attach to a container

  • Posted September 11, 2014

I can manage Ubuntu in a docker container and install/configure nginx.

But here’s one:

sudo docker pull stilliard/pure-ftpd

Then it says, “Once inside” Create an ftp user: e.g. bob with access only to /home/ftpusers/bob

How do I get inside, I already tried using docker attach ‘container’ and I can’t connect.

Here’s another one: After few seconds, open http://<host> to see the welcome page.

It works!

But I can’t find the nginx folder anywhere or to access the placeholder.


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Generally you don’t want to be making changes to a live Docker container as they don’t save the state. If you need to do something like create a user inside the container, you’re probably better off doing this in the Dockerfile. Though attaching to a running container is possible. First run docker ps to find the container’s ID. Then you can enter the container with:

docker attach CONTAINER_ID

For your Nginx example http://<host> , the host is the IP address of the machine running Docker. If you want to access files inside the container, it’s better to bind mount them from the host. That way they are persistent. For instance, running:

docker run -d -p 80:80 -v /etc/nginx/sites-enabled:/etc/nginx/sites-enabled -v /var/www/html:/var/www/html dockerfile/nginx

will mount the host folders /etc/nginx/sites-enabled and /var/www/html inside the container.