Get the App
SLTechnology News&Howtos  ›  Servers  › 

Why do you keep running docker containers?

Shulou Source: shulou.com Published: 2022-06-02 00:20:49 09月16日 Update

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.

Tags: Containers runs commands background content that is skills status knowledge threading concise important concise interactive foreground reasons suggestions articles methods more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Redmi Shulou Technology Microsoft macOS