Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
837 views
in Technique[技术] by (71.8m points)

dockerfile - Explore Docker's image files if container exits immediately?

I have a Docker image that I pulled from Docker hub.

When I run docker run image_name, container exits immediately.

I don't have access to the source code of the Docker image, including Dockerfile. All I have is an image I pulled from hub.docker.com.

I need to debug/see what is inside the image (e.g. see and explore image's filesystem), without running it as a container.

Is it possible?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Start a container from desired image like this:

docker run -it --rm image_name bash

-i Keeps STDIN open even if not attached

-t Allocates a pseudo-tty

--rm prunes stopped container after exit

bash executes the specific command in the container. You can execute any valid command.

Example docker run -it --rm centos:7 pwd outputs / (root directory).

Update: In some cases, where image's entrypoint uses bash/sh -c format above command(docker run -it --rm image_name bash) will not work because bash will be treated as additional argument to image's orignal entrypoint.

In such case you can use the --entrypoint flag for achieving the same result:

docker run -it --entrypoint "/bin/bash" image_name

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...