Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

stratboy's avatar

How to rename a docker container name in docker desktop?

Hi, when I open Docker I have the 'containers' view. That lists my current 2 containers. It seems there're no gui to rename a container. How to? I tried with terminal with docker rename but it says it doesn't find the container. And it's probably right, but I mean the 'main' name, the one that you can open and then see the real containers that get listed with docker ps -a. I need to rename it because I'm going to create another project with exactly the same name.

0 likes
2 replies
LaryAI's avatar
Level 58

To rename a Docker container, you can use the docker rename command in the terminal. However, it seems like you might be having trouble finding the correct container name. Here’s a step-by-step guide to help you rename your Docker container:

  1. List all running containers: First, you need to find the exact name of the container you want to rename. You can do this by listing all running containers using the following command:

    docker ps
    

    If the container is not running, you can list all containers (including stopped ones) with:

    docker ps -a
    
  2. Identify the container: Look for the container you want to rename in the list. Note the current name of the container.

  3. Rename the container: Use the docker rename command to rename the container. The syntax is:

    docker rename <current_name> <new_name>
    

    For example, if your current container name is my_old_container and you want to rename it to my_new_container, you would run:

    docker rename my_old_container my_new_container
    
  4. Verify the rename: To ensure the container has been renamed, you can list the containers again:

    docker ps -a
    

Here’s a complete example:

  1. List all containers to find the current name:

    docker ps -a
    

    Output might look like this:

    CONTAINER ID   IMAGE         COMMAND                  CREATED          STATUS                      PORTS     NAMES
    1a2b3c4d5e6f   my_image      "some_command"           2 days ago       Exited (0) 2 days ago                 my_old_container
    
  2. Rename the container:

    docker rename my_old_container my_new_container
    
  3. Verify the rename:

    docker ps -a
    

    Output should now show the new name:

    CONTAINER ID   IMAGE         COMMAND                  CREATED          STATUS                      PORTS     NAMES
    1a2b3c4d5e6f   my_image      "some_command"           2 days ago       Exited (0) 2 days ago                 my_new_container
    

If you follow these steps, you should be able to rename your Docker container successfully. If you still encounter issues, make sure that the container name you are trying to rename exists and that you have the necessary permissions to rename it.

martinbean's avatar

@stratboy You can set a COMPOSE_PROJECT_NAME=foo variable in your .env file, and then Sail (or Docker Compose if you make it source your .env file) will use than name for the stack it creates.

Please or to participate in this conversation.