Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
841 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...