V
V
vldanch2019-01-31 14:08:00
Database design
vldanch, 2019-01-31 14:08:00

How to dump postgressql database from one docker container to another?

Good afternoon, I ask for tips on how to dump the postgressql database from one container to another?
I sketched out the code and I managed to make it only into a separate file, but how can I pour it directly into the container?

docker run --name dbdata postgres echo "Data-only container for postgres" # Создаем наши контейнеры
docker run -d --volumes-from dbdata --name db1 postgres # Применяем аргумент для первого контейнера --volumes-from
docker run -d --volumes-from dbdata --name db2 postgres # Применяем аргумент для второго контейнера --volumes-from
docker exec -i -t db1 bash #Подключчаемся к первому контейнеру
docker exec -i -t db2 bash #Подключчаемся ко второму контейнеру
apt-get update; apt-get install sudo # Обновим и установим sudo
sudo -i -u postgres # Заходим в бд postgresql
createdb my_db #создаем нашу базу данных
docker exec db1 pg_dump -U postgres -F t my_db > my_db-$(date +%Y-%m-%d).tar.gz # Делаем дамп базы данных в фаил

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sim3x, 2016-06-21
@sim3x

PostgreSQL
самая быстроразвивающаяся и стабильная

B
beduin01, 2016-06-21
@beduin01

SQLite

S
Saboteur, 2019-01-31
@saboteur_kiev

so if you use the same --volumes-from dbdata, you have the disk mounted in both containers, so this file should simply be available in the other container.
The only question is where do you store the data itself? right on a primed volum?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question