# How to mount storage on a running docker container

Mounting storage on a running Docker container isn’t directly supported, but there are reliable workarounds to achieve similar results. Below, you’ll find two practical methods with step-by-step instructions and relevant citations.

---

## Method 1: Copy Files Directly with `docker cp`

While you cannot mount a new volume on a running container, you can transfer files between your host and the container using the `docker cp` command. This is useful for one-time file transfers but does not create a persistent mount.

**Command Syntax**:

```plaintext
bash# Copy from container to host
docker cp <containerId/containerName>:/path/in/container /path/on/host

# Copy from host to container
docker cp /path/on/host <containerId/containerName>:/path/in/container
```

**Example**:

```plaintext
bashdocker cp my_container:/app/config.json ./local_dir
docker cp ./updated_file.txt my_container:/app/data
```

**Limitations**:

* No real-time synchronization; changes are not automatically reflected.
    
* Manual process; must be repeated for each transfer[2](https://kodekloud.com/blog/docker-cp/).
    

For more details, see the \[Docker documentation on `docker cp`\][2](https://kodekloud.com/blog/docker-cp/).

---

## Method 2: Commit and Recreate the Container with a Volume

For persistent storage, the best approach is to commit your running container to a new image and then launch a new container with the required volume mount.

**Steps**:

1. **Commit the existing container**:
    
    ```plaintext
    bashdocker commit <containerId or containerName> new_image_name
    ```
    
2. **Run a new container with a volume**:
    
    ```plaintext
    bashdocker run -v /host/path:/container/path -it new_image_name /bin/bash
    ```
    

**Example workflow**:

```plaintext
bashdocker commit agitated_newton my_ubuntu
docker run -v "$PWD/somedir":/somedir -it my_ubuntu /bin/bash
```

**Advantages**:

* Enables persistent storage via Docker-managed volumes or bind mounts[1](https://docs.docker.com/engine/storage/volumes/)[6](https://docs.docker.com/engine/storage/).
    
* Retains changes made in the original container.
    

**Note**: This method requires stopping the old container and using the new one for continued work[4](https://betterstack.com/community/questions/how-to-add-volume-to-existing-docker-container/).

---

## Why Can’t You Mount Storage Directly on a Running Container?

Docker’s architecture does not support adding new mounts to a running container. Mounts (volumes, bind mounts, tmpfs) must be specified at container creation using the `--mount` or `-v` flags[1](https://docs.docker.com/engine/storage/volumes/)[6](https://docs.docker.com/engine/storage/). For persistent or shared storage, always plan your mounts before starting the container.

---

## Summary Table

| **Scenario** | **Method** | **Reference** |
| --- | --- | --- |
| One-time file transfer | `docker cp` | [2](https://kodekloud.com/blog/docker-cp/) |
| Persistent storage needed | Commit & rerun | [1](https://docs.docker.com/engine/storage/volumes/)[4](https://betterstack.com/community/questions/how-to-add-volume-to-existing-docker-container/)[6](https://docs.docker.com/engine/storage/) |

---
