How do I attach to a container

September 11, 2014 3.4k views

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

But here's one: https://github.com/stilliard/docker-pure-ftpd

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.

1 Answer

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.

Have another answer? Share your knowledge.