I'm trying to access a docker image without running, I just want to know what it contains for verification. I cannot ssh into the container as the it ends in just a second, so I need to explore the image and not the container. or Is there anyway to access the container before it completes?
Asked
Active
Viewed 2.6k times
3
-
Possible duplicate of [Exploring Docker container's file system](http://stackoverflow.com/questions/20813486/exploring-docker-containers-file-system) – d_schnell Aug 09 '16 at 19:41
-
Not exactly a duplicate, as I was trying to explore an image not a container. – Grat Aug 09 '16 at 21:14
-
Possible duplicate of [How to access an docker's image file system](http://stackoverflow.com/questions/32383487/how-to-access-an-dockers-image-file-system) – Yan Foto Aug 10 '16 at 08:49
2 Answers
6
Got it, here is the command:
docker run -i -t image/container /bin/bash

Grat
- 103
- 1
- 1
- 7
-
yes, as I thought it was not possible to ssh into a running container whose runtime is about a second. – Grat Aug 09 '16 at 21:10
-
-
1I suppose this works (I haven't tried, but I trust it works for you). I wanted the same thing, and my elder brother helped me with the following: docker run --entrypoint=/bin/bash [image] This also doesn't provide a way to do it without "running", but as I suspect your solution operates, it will skip running the default entry point, and give you bash instead. That way you can look around and do what you want before actually running it the default way. In a way - I think this does actually qualify as NOT running. – Jason Cramer Feb 28 '17 at 05:55
4
It's pretty cumbersome to actually explore an image. The docker save
command's output isn't very friendly. You're better off working with a container. But you don't have to run a container to do this.
You can use the docker create
command with a few others to explore a container without running it:
docker pull alpine
docker create --name foo alpine false
docker export foo | # Export the entire filesystem as a tape archive
tar -tf- | # Use tar to output the names of files
less # pipe to less to page the output
If you want to examine a single file, you can use docker cp
, like so:
docker cp foo:etc/passwd - | tar -xO | head -n3
root:x:0:0:root:/root:/bin/ash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
You can really get away without using the pipeline in the last statement; you'll get some tar junk at the top, but it doesn't matter if you're just exploring.

kojiro
- 74,557
- 19
- 143
- 201