Mounting At Runtime Into A Container

docker run --name <container_name> -v <absolute_local_path>:<absolute_container_path>
  • run --name <container_name>: Name of the running container
  • -v <local-path>:<container-path>: Local directory path (left-side) & Container directory path (right-side)

Mounting At Startup Time Into A Container

docker run -it --rm -v local/path:container/path image:tag
  • -i(interactive): Keeps STDIN open so you can interact with the container even if not attached.
    • It allows you to send input to the container.
  • -t(tty): Allocates a pseudo-TTY terminal inside the container.
    • This makes the container’s console more readable and interactive, like a normal terminal sessions.
  • --rm: Automatically removes the container when it exits.
    • Prevents stopped containers from running in the background, and cleans up after the container stop running.
  • -v local/path:/container/path: Bind mounts a directory or file form the host machine to the container’s file system at runtime.
    • Changes made locally will be reflected immediately in the container, since it’s was mounted not copied.
  • image:tag: Name of the Docker image and it’s respective tag.