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.

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.

Kubernetes Series
- Introduction to Kubernetes
- Introduction to Docker, Containers, Images & Repository
- Install and Run Docker Images
- Docker Image – FROM, RUN, COPY, ENTRYPOINT, CMD, EXPOSE explained
- Why docker run or start command not running my container?
- How to list all docker images in system?
- How to list all docker containers?
- How to start/stop a docker container?
- Difference between docker run and docker start
- How to bind docker container port with host?
- How to get logs of docker container?
- How to live stream logs of docker container?
- Set custom name to a docker container
- Access docker container filesystem & terminal
- Getting docker details using docker inspect
- Kyverno – Installation, Policies, Testing, Reporting, Monitoring, Security
- Complete Kubernetes Project Step By Step
- Introduction to Kubernetes Objects