Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to rename a container in docker

Shulou Source: shulou.com Published: 2022-06-01 11:07:52 11月13日 Update

This article mainly explains "how to rename a container in docker". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to rename a container in docker.

When you create a docker container, it is assigned a globally unique identifier (UUID). This is essential to avoid naming conflicts and to move away from human intervention to promote automation.

Docker also supports containers with a randomly generated name of 2 words, highlighted with a bottom line, such as evil_ptolemy. This makes it easier to tell a person which container it is. But random names don't give people more insight into the operation of the container than UUID does.

Naming when you run the container

By adding-name=meaningful_name to let docker run commands, an evil_ptolomy becomes more recognizable in the interaction process and like docker ps output commands. However, this has its limitations. After the automatic container name must be unique, you cannot use a questionable name and the size of the service exceeds one container.

On the command line or in a file:

Docker run-name=meaningful_name

For example: if we run a container based on the Nginx base image and start like this:

Docker run-- name nginx-d nginx

The name is displayed in the list of running containers:

Docker psOutputCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES08f333ef7216 nginx "nginx-g'daemon off" 15 seconds ago Up 14 seconds 80/tcp, 443/tcp nginx

When the docker ps name appears in the output and can be used to manage the container, it will not appear in the container's command prompt if you link it or in the log file.

Rename docker Container

Please use the name subcommand, docker rename the original container name and the new container name. In the following example, we renamed the container discourse_app to the new name disc_app.

$sudo docker rename discourse_app disc_app

After renaming the container, verify that it now uses the new name.

$sudo docker ps

For more information, see the docker-run man page.

$man docker-run

Thank you for reading, the above is the content of "how to rename containers in docker". After the study of this article, I believe you have a deeper understanding of how to rename containers in docker, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Container name command run name more learning content file this is output global word foundation that is limitation bottom line essential idea situation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Apple Xiaomi vpn Huawei