docker service create --name db --mount type=volume,source=dbdata,target=/var/lib/postgresql/data postgres:16

Category: Docker

docker service create --name db --mount type=volume,source=dbdata,target=/var/lib/postgresql/data postgres:16

Create a service with a data volume

Mounts the named volume dbdata at the container's data directory so database files survive task rescheduling. Service mounts use the same --mount syntax as docker run. Volume lifecycles are independent of the service.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.