Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

accessing a docker container's file system through terminal

Tags:

So I have successfully downloaded and got running the dockerfile/nginx image from the registry. How can I now access its file system by firing up a bash terminal on it?

Maybe I am missing something conceptually here. Do I need to ssh into it? thanks

like image 771
Zuriar Avatar asked May 01 '14 10:05

Zuriar


People also ask

What command can you use to view a container's logs?

First of all, to list all running containers, use the docker ps command. Then, with the docker logs command you can list the logs for a particular container. Most of the time you'll end up tailing these logs in real time, or checking the last few logs lines.

How do I connect docker container to terminal?

The docker exec and docker attach commands allow you to connect to a running container. To get an interactive shell to a container, use the exec command to start a new shell session. The attach command attaches your terminal to a running container.


1 Answers

You can start an interactive shell in a new image:

sudo docker run -i -t nginx /bin/bash 

This gives you access to the container and you can change things. When done you need to save your changes in a new reusable image:

sudo docker commit <container_id> <some_name> 

This approach makes sense for testing. Usually you would use Dockerfiles to automate this.

In case your image has a default entry point you can overwrite it:

docker run -i -t --entrypoint /bin/bash nginx 
like image 67
Sebastian Avatar answered Oct 06 '22 19:10

Sebastian