Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

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.

share|improve this question

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.

share|improve this answer

You could try this:

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.