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](https://i0.wp.com/authors.akashmittal.com/wp-content/uploads/2022/07/image-22.png?resize=820%2C143&ssl=1)
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](https://i0.wp.com/authors.akashmittal.com/wp-content/uploads/2022/07/image-23.png?resize=820%2C527&ssl=1)
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