From the course: Docker for Developers: Create and Manage Docker Containers

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Using a Docker volume

Using a Docker volume

- [Instructor] Volumes are your best friend for saving data between container restarts. Without them, every time you take down your database container, your data disappears. Volumes give you data persistence, and setting them up is simple. Take a look at your compose file in VS Code. At the bottom of the file on line 23 we're defining a volume. We're naming it pgdata. This volume can be used by any service defined in the compose file. If this volume doesn't exist, Docker Compose will create it for you when you run the containers. The only service that needs to use this volume is the DB service. On lines 20 and 21, the volume is set by using the name of the volume and a colon. The file path here is the location inside the container where the volume is mounted. If you wanted to create this volume before running the DB container, you would use the docker volume create command, and then the name of the volume. This…

Contents