Docker Rename container from the command line and GUI

You may be running several Docker container instances in your lab environment and elsewhere. Docker container environments are becoming increasingly common for self-hosted services. Docker containers allow spinning up services quickly and running services more efficiently than in virtual machines if the services support running in containers. When you get many different Docker containers up and running, you may need to rename Docker container instances from time to time. Let’s look at how to rename docker container instances and see the steps involved.

What are Docker containers?

Docker containers are becoming more common and important in enterprise infrastructure and modern applications. Most modern applications run inside containers and not virtual machines.

Docker containers can be easily bundled in Docker images and stored in a repository, such as Docker hub. The docker daemon is a process that runs on the container host and allows

What is a Docker container name?

When working with Docker containers, these have a container ID and a container name. The container name is a friendly name for the Docker container, whereas the container ID is a randomly generated alphanumeric string that is a unique identifier for each container and is generated with new container instances when spun up.

Docker container naming conflicts

One of the important things to note with Docker container names is there must not be any container naming conflicts.

If you attempt to rename a container to a name that is already in use, you will see the error:

Error response from daemon: Error when allocating new name: Conflict. The container name “/<container name>” is already in use by the container.

Why rename the Docker container?

You may wonder why you need to rename a container. If you accept the defaults in Docker when running containers if you don’t supply a name by default, it spins up a randomly generated container name.

Below, you see a randomly generated container name.

The randomly generated container name is not intuitive. So, it makes it more difficult to work with your containers with these randomly generated container names.

Docker rename command

The docker command line command contains a docker rename command, and a rename subcommand, allowing you to rename a Docker container to a new name. Note the following command output from the command docker rename –help.

The docker container rename command renames an existing docker container name to the name you configure. The docker rename command renames one container to another container name.

As shown below, you can rename one or more containers using the docker rename command. The syntax is:

docker rename CONTAINER NEW_NAME

Docker rename command example

In the following example, let’s rename a container called serene_einstein to a new container name.

We use docker rename <existing name> <new name>

Docker images rename

As a note, there is no rename for a docker image functionality built into the Docker command line. So, the best way to rename a docker container is to export an existing container image to another. You can also save a running container to create new container image automatically.

Rename from the GUI

Using Portainer or another GUI management tool allows renaming Docker containers from a GUI management tool. Using Portainer, you can select a container and then edit.

Once you edit a container, you can then edit the Name field.

Wrapping Up

Hopefully, this quick look at performing a Docker command will help show how to carry this task out quickly and easily. It is basically as easy to rename a docker container as it is to rename a file from the command line.

Also, using a GUI tool like Portainer, you can perform a Docker rename container command to rename the friendly name of a Docker container to a new name.

Post a Comment

0 Comments