Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The created docker container cannot be accessed. What's going on?

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you the creation of the docker container can not access what is going on, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

Sometimes when we create a container through an image, we use the command: docker run-- name docker-test-d learn/ping / bin/sh. After running successfully, we find that the container does not run in the background as expected, but simply hangs up, and docker ps-a finds that the container has finished running.

Looking for information, it is found that the reason is: if the Docker container runs in the background, there must be a foreground process. The commands run by the container will exit automatically if they are not those that have been suspended (such as running top,ping).

The / bin/bash in the above code is the specified command that needs to be executed. If the command is finished, or when the specified application is terminated, the container will stop automatically. The command / bin/bash must end as soon as it is executed.-d means that the container runs in a daemon state, and a container ID is returned after startup.

Since a short command will cause the container to finish running, try a command that lasts for a long time, such as top,ping, so change the command to docker run-- name docker-test-d learn/ping ping www.baidu.com, or directly start the suspended container, docker start learn/ping, container id can be viewed through docker ps-a.

Then, execute docker ps and you will find that the container is up, and then docker attach learn/ping enters the container's interactive interface, or docker run-it learn/ping / bin/bash goes directly to the interactive interface.

You can exit using ctrl+d or ctrl+c, or ctrl+p + ctrl+q. (this allows you to exit to the host while keeping container still running, as can be seen through docker ps.) the former method exits and the container ends, and in the latter way, the container still runs in the background.

The above is all the content of the article "what's wrong with the created docker container?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report