How to access docker container filesystem and terminal?

Total
0
Shares
access docker container filesystem and terminal

To access docker container filesystem and terminal, use this command –

docker exec -it {container_id} /bin/bash

Here the choice of terminal depends on the flavor of operating system used by container image. Some of them uses /bin/bash while some uses /bin/sh.

For mongodb container, my-mongo-container, which we created in our last article, the command works like this –

docker exec -it my-mongo-container /bin/bash

It will attach the bash terminal of the container to the host command line.

open bash terminal of the container

From the image you can see that we have successfully attached the bash terminal of our mongo container. Now we can run any terminal command like ls, pwd, cd etc. This way you can access the whole filesystem of this container.

running terminal commands in container