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

Why do you keep running docker containers?

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

Share

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

This article shows you how to run the docker container all the time, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Phenomenon

Start the docker container

Docker run-name [CONTAINER_NAME] [CONTAINER_ID]

View container running status

Docker ps-a

Found that the mydocker container that has just been started has exited

Reason

It is important to note that when the Docker container runs in the background, there must be a foreground process.

If the commands run by the container are not those that have been suspended (such as running top,tail), they will exit automatically.

The main thread of the docker container (the command executed by CMD in dockfile) ends and the container exits

Solution method

You can use interactive startup

Docker run-I [CONTAINER_NAME or CONTAINER_ID]

The above is not very friendly, it is recommended to use background mode and tty option

Docker run-dit [CONTAINER_NAME or CONTAINER_ID]

View container status

Docker ps-a

Docker calls up the backend container

Docker attach [CONTAINER_NAME or CONTAINER_ID]

TIPs: when exiting, use [ctrl + D], which ends the current thread of docker and the container. You can use [ctrl + P] [ctrl + Q] to exit without terminating the container.

The following command will execute the specified command in the specified container. The container will not be terminated after [ctrl+D] exits.

Docker exec-it [CONTAINER_NAME or CONTAINER_ID] / bin/bash this is how to run the docker container all the time. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are 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