How to open docker containers file system

0 votes

I'm new to docker and I want to know how I can explore docker containers from the inside. Like what files exist inside of it. For Eg. when I download images from the docker index, I don't know what that image contains so it's impossible to start the application.

What should I do? Is there a way to SSH into them?

Jun 27, 2019 in Docker by shubham
• 7,340 points
20,445 views

2 answers to this question.

0 votes

There are various ways you can do this:

Method 1: Snapshoting

You can go through the container filesystem:

# find ID of your running container:
docker ps

# create image (snapshot) from container filesystem
docker commit 12345678904b5 mysnapshot

# explore this filesystem using bash (for example)
docker run -t -i mysnapshot /bin/bash

By doing this you can check the filesystem of running container in that moment in time. The container would still be in running condition with no future changes included.

After, you could delete this snapshot:

docker rmi mysnapshot

Method 2: SSH

If you want something continuous, you can use SSHD. You'll have to install it on your container and then execute SSHD Daemon:

 docker run -d -p 22 mysnapshot /usr/sbin/sshd -D

 # you need to find out which port to connect:
 docker ps

This way you'll be able to run you application using SSH.

Method 3: docker exec

If bash is present on your container you can directly use shell on your container by using:

docker exec -t -i mycontainer /bin/bash

Check Docker CLI documentation

answered Jun 27, 2019 by DareDev
• 6,890 points
0 votes

Adding on to @DareDev's answer there's one more method.

Method 4: Use nsenter

with nsenter, you can get a shell into an existing container, even if that container doesn’t run SSH or any kind of special-purpose daemon.

For more info see http://blog.docker.com/2014/06/why-you-dont-need-to-run-sshd-in-docker/

answered Aug 5, 2019 by Sirajul
• 59,230 points

Related Questions In Docker

+1 vote
2 answers

How to run docker containers on different machines

You can use labels and selectors for ...READ MORE

answered Oct 23, 2018 in Docker by Laila
3,544 views
0 votes
1 answer

How to obtain the Docker container's IP address from the host?

This can be done by executing the ...READ MORE

answered Jul 17, 2018 in Docker by Sophie may
• 10,620 points
8,840 views
+1 vote
1 answer

How to remove old Docker containers

There is a new feature in Docker 1.13.x called Docker ...READ MORE

answered Jul 18, 2018 in Docker by Kalgi
• 2,680 points
710 views
0 votes
1 answer

How to list containers in Docker

To show only running containers use the given command: docker ...READ MORE

answered Jul 20, 2018 in Docker by Kalgi
• 52,350 points
777 views
+2 votes
1 answer
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,100 points
2,687 views
0 votes
1 answer

How to send docker using terraform to aws cloudwatch?

Check if you set all the permissions ...READ MORE

answered Jun 7, 2018 in Docker by DareDev
• 6,890 points
2,906 views
+4 votes
7 answers

If conditional in docker file

First of all, create a build_internal.sh file ...READ MORE

answered May 29, 2018 in Docker by DareDev
• 6,890 points
123,238 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP