I am using a docker-compose.yml file to build 3 docker containers for my django nginx postgresql and a pure 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 concerns on how to backup and restore the postgresql data stored in the pure data container(myweb_data_1). I use "docker-compose build && docker-compose up" command to rebuild docker images and restart containers if I update the codes, but not sure if this is right or best way to do it.
Run PostgreSQL on Docker Containers The first option uses Docker Compose, a tool for managing multi-container Docker applications. You can use Docker Compose to configure the Postgres as a service running inside of a container. In that case, you create a yaml file with all the specifications.
I do not have experience with postgresql, but from a docker point of view this approach seems perfectly fine. Your data will be in the data-container. It will not be affected by docker-compose build && docker-compose up
. Raman Gupta gives a good introduction into this topic in his article.
In that he also stresses that you need the proper mindset for data-only-containers. For you this means, you can have a "backup-container". Use the postgres
image and run a new container from it, which uses --volumes-from myweb_data_1
. Now in the container you do have the proper tools from postgresql and access to your database in the data-container.
Again, postgresql might be different, but for mysql this is the way, which works perfectly fine and is to my understanding a best practice. By the way, mysql is a server. So you would start a new container and link it (--link
) against your myweb_db_1
container. Not sure how postgresql behaves.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With