Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose for a pure data container and web server, postgresql

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.

like image 417
Liao Zhuodi Avatar asked Apr 17 '15 01:04

Liao Zhuodi


People also ask

Which docker command will you use to execute commands to a PostgreSQL docker container?

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.


1 Answers

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.

like image 197
Jan Suchotzki Avatar answered Oct 10 '22 17:10

Jan Suchotzki