Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access a docker image?

Tags:

docker

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?

like image 830
Grat Avatar asked Oct 22 '25 06:10

Grat


2 Answers

Got it, here is the command:

docker run -i -t image/container /bin/bash
like image 191
Grat Avatar answered Oct 23 '25 21:10

Grat


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.

like image 29
kojiro Avatar answered Oct 23 '25 21:10

kojiro