How to Save Docker Data using Bind Mounts or Volumes

preview_player
Показать описание

Using Docker for a database is common during development. It’s easy to set up, and it’s available for many different types of databases.

One drawback is that the data is not saved when the container is removed.

However, there are two methods that can be used to save data in Docker if a container is removed.

These methods are Volumes and Bind Mounts.

In this video, I’ll explain what they are and show you how to set up a container to use each of them.

We’ll use a MySQL database to demonstrate that the database is saved between containers, but this works on many different databases.

This video assumes you have Docker set up already. If not, you can check out any of my other videos:

Timestamps:
00:00 Introduction
00:16 Docker storage options
01:05 Definitions
01:40 Prerequisites for this video
02:02 Option 1: Create volume
03:00 Docker run with volume
04:35 Add data to database
06:16 Remove and create new container
08:42 Option 2: Create bind mount
09:26 Docker run with bind mount
10:54 Add data to database
11:58 Remove and create new container
Рекомендации по теме
Комментарии
Автор

Perfect for me. Instead of reading documents I always love to "feel" it with some handson examples. It saved my time. Thanks

joachimhans
Автор

this is a very great video with a clear and concise explanation of volumes and bind mounts... the best one ever.

hardworkerbig
Автор

every tutorial should be like this. quick and well explained

bjorn
Автор

I saw many videos, but your video finally settled my confusion. Many thanks.

brotherdavy
Автор

perfect. time efficient and informative tutorial. no time wasting. keep it up 👍

manojsinghnegi
Автор

Great Video ! ! !
I too was confused by reading different google explanations. This video quickly and clearly explained the concepts. All the examples worked just fine on my machine - a linux machine.
Thank You ! ! !

pbanta
Автор

I have been searching a lot about this subject and what you did is the best one

jackq
Автор

Thank you man was looking for this, it cleared up confusion, may Allah bless you with Islaam.

anoniem
Автор

Thank you so very much! you really helped me understand how containers use volumes and binds and what is happening setting up my YAML files.

svgenterprises
Автор

You should post more videos on docker and kubernetes

nishitkumar
Автор

very informative and clear, thanks. What if your computer host break completely? Whar are your backup strategies to save elsewhere either a bind mounts or volumes with your data inside?

jeytis
Автор

thank you for your efforts preparing this great and informative video. If I may, I have a question. how about connecting to an existing database server that is on a different machine/host outside of the Docker host? did you come across this use-case in your research. would appreciate your input on this. thx in advance.

indylawi
Автор

Thank you so much for this detailed video. I had one question. When I try to do the bind method my target is "/var/lib/postgresql/data" and I am getting a permission denied error:

chmod: changing permissions of '/var/lib/postgresql/data': Operation not permitted

It works if I choose any other location including "/var/lib/postgresql" but the data I wish to copy is inside data. Please let me know if you are familiar with this? Thank you again.

maheshyarasi
Автор

Great video Gentelman, sub and like for you, keep up with the good work, happy to be there

dawidgrzeskow
Автор

It removed my confusion about volume and bind mount.

redwansikder
Автор

Great video, thanks very much. The --mount type=bind function and how it was working for you in the vid is exactly what I'm looking for but I can't seem to get it working for my windows folder (D:\test). I used --mount type=bind, source=//d/test, target=/opt/drupal so I could see and access what's inside the drupal folder. The command is executed successfully and the container is created, but won't work :( Any ideas on that?

spill
Автор

Getting this error. [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.40-1.el9 started.
chown: changing ownership of '/var/lib/mysql/': Permission denied
chown: changing ownership of '/var/lib/mysql': Permission denied

Mj-Lahir
Автор

How would you copy a volume from a test server to a production server?

bokkenka
Автор

How to persist data in postgres?
I tried using this docker command, docker run --name learn_postgres -e -d postgres --mount source=postgres-volume, target=/var/lib/postgresql/data -p 5432:5432

but once I checked container status using docker ps -a
I see exited my container just after creation.

AbdulBasit-ibby
welcome to shbcf.ru