Running with persistent volumes
The command provided for running the Docker container does not create a "persistent volume" in the Docker sense but mounts a host directory into the container at runtime.
The --volume
(or -v
) flag is used to mount a file or directory from the host into the container.
This allows for sharing files between the host and the container. Here's a breakdown of the docker run
command and its implications for persistence:
--rm
: Automatically removes the container when it exits. This means that any data or changes made inside the container that are not in a volume or bind-mounted directory will be lost.-it
: Runs the container in interactive mode with a tty, allowing you to interact with the container via the command line.--ipc=host
,--ulimit memlock=-1
,--ulimit stack=67108864
,--gpus=all
: Various options to configure the container's system resources and GPU access.--volume ${PWD}:/code/tensorrt_llm
: Mounts the current working directory (${PWD}
) on the host to/code/tensorrt_llm
inside the container. This is where the persistence aspect comes into play, but it's based on a host directory, not a Docker-managed volume.--workdir /code/tensorrt_llm
: Sets the working directory inside the container to/code/tensorrt_llm
.
Persistence Explained
The persistence of data using the --volume
flag is tied to the lifecycle of the host directory being mounted. This means:
Within the Container: Any changes made inside the container to the contents of
/code/tensorrt_llm
will reflect back to the${PWD}
on the host, and vice versa. This allows for a persistent development workflow where changes made on the host can be immediately reflected and tested within the container.Across Container Sessions: Because the data lives on the host and is merely mounted into the container, it persists across multiple
docker run
invocations, as long as you mount the same host directory each time.
Docker Volumes vs. Bind Mounts
The approach described above uses a bind mount (mounting a host directory), not a Docker-managed volume.
Docker volumes are managed by Docker and are a more robust solution for persisting data generated by and used by Docker containers.
They're stored in a part of the host filesystem managed by Docker (/var/lib/docker/volumes/
on Linux).
Unlike bind mounts, volumes are completely managed by Docker and abstract away the underlying operating system details, providing a more portable and encapsulated way to handle data persistence.
Last updated