# How to upgrade the docker container after its image changed?

To upgrade a Docker container after its image has changed, you can follow these steps:

1. Stop the container using the following command:
    
    ```bash
    docker stop <container_name_or_id>
    ```
    
    Replace `<container_name_or_id>` with the name or ID of the container you want to upgrade.
    
2. Remove the container using the following command:
    
    ```bash
    docker rm <container_name_or_id>
    ```
    
    This will remove the container and **any data stored inside the container will be lost.**
    
    Note that when you remove a container, any data stored inside the container is lost. To avoid losing data, you can use Docker volumes to store data outside the container. This way, when you create a new container using an updated image, you can attach the same volume to the new container and the data will still be available. To learn more about Docker volumes, you can check the official documentation.
    
3. Pull the latest version of the image using the following command:
    
    ```bash
    docker pull <image_name>
    ```
    
    Replace `<image_name>` with the name of the Docker image you want to use to create the new container.
    
4. Create a new container using the updated image and any desired options. For example, you can use the following command to create a new container from the updated image and map a port:
    
    ```bash
    docker run -p 8080:80 --name <new_container_name> <image_name>
    ```
    
    Replace `<new_container_name>` with the name you want to use for the new container and `<image_name>` with the name of the Docker image you want to use to create the container.