Docker Cheat Sheet/Mount named volume in container

Run a container with a named volume.

Section: Volumes and Mounts

Mount named volume in container

bash
bash
docker run -d --name db -v pgdata:/var/lib/postgresql/data postgres:16
Explanation

Common for persistent databases and stateful services.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Volumes and Mounts
Run a container
Create and start a new container.
OpenIn sheetbash1 tag match
Run detached
Run a container in the background.
OpenIn sheetbash1 tag match
Run interactively
Run an interactive shell inside a new container.
OpenIn sheetbash1 tag match
Set environment variables
Pass environment variables into the container.
OpenIn sheetbash1 tag match
Load env file
Load environment variables from a file.
OpenIn sheetbash1 tag match
Mount a bind volume
Bind-mount a host directory into the container.
OpenIn sheetbash1 tag match