docker run mount volume code example

Example 1: docker mount volume

docker run -v /host/directory:/container/directory -other -options image_name command_to_run

Example 2: docker build mount volume

$ docker run -it -v "$(pwd)/source_dir:/app/target_dir" ubuntu bash
# OR
$ docker run -it --mount "type=bind,source=$(pwd)/source_dir,target=/app/target_dir" ubuntu bash

Example 3: docker exec mount volume

#make sure that you are inside the same directory
docker run -v pwd:/container/directory -other -options image_name command_to_run

Example 4: start a docker container

$ docker start <container_id>