Docker-compose for a clean data container and web server, postgresql

I am using the docker-compose.yml file to create 3 docker containers for my jango nginx postgresql and a clean data container.

Here is my docker-compose.yml

data: # pure data container image: busybox volumes: - /etc/postgresql - /var/log/postgresql:/var/log/postgresql - /var/lib/postgresql - /var/log/nginx:/var/log/nginx - /var/log/supervisor:/var/log/supervisor db: image: postgres volumes_from: - data web: build: . ports: - "80:80" - "443:443" links: - db volumes_from: - data $docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES cc26b3a72a02 myweb_web:latest "supervisord -n" 6 minutes ago Up 6 minutes 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp myweb_web_1 14763a9f68d1 postgres:latest "/docker-entrypoint. 6 minutes ago Up 6 minutes 5432/tcp myweb_db_1 37598892038b busybox:latest "/bin/sh" 6 minutes ago Exited (0) 6 minutes ago myweb_data_1 

I have problems backing up and restoring postgresql data stored in a clean data container (myweb_data_1). I use the docker-compose build & docker-compose up command to restore docker images and restart containers if I update the codes but are not sure if this is correct or the best way to do it.

+6
source share
2 answers

I have no experience with postgresql, but from a dockers point of view, this approach seems perfectly fine. Your data will be in the data container. docker-compose build && docker-compose up will not affect it. Raman Gupta gives a good introduction to this topic in his article.

In this, he also emphasizes that you need the right mindset for data-only containers. For you, this means that you may have a "backup container". Use the postgres image and start a new container from it, which uses --volumes-from myweb_data_1 . Now in the container you have the appropriate tools from postgresql and access to your database in the data container.

Again, postgresql may be different, but for mysql it is a way that works fine and works best for me. By the way, mysql is a server. So you have to start a new container and bind it ( --link ) with the container myweb_db_1 . Not sure how postgresql works.

+3
source

You can try the following:

docker run --volumes-from myweb_data_1 -v $ (pwd): / backup ubuntu tar cvf / backup / backup.tar

0
source

Source: https://habr.com/ru/post/985316/


All Articles