F
F
furyon2016-03-16 16:34:20
Docker
furyon, 2016-03-16 16:34:20

How to run script in container via docker-compose?

Hello!
I am learning docker-compose. I'm looking for a way to dump a database from a container. Let's say we have docker-compose.yml:

postgres:
  image: postgres:9.5
  volumes_from:
    - postgres-data
  volumes:
    - ./dump:/backup

postgres-data:
  image: busybox
  volumes:
    - /var/lib/postgresql/data

So far, I've managed to solve the trace problem by:
I write docker ps -a , I'm looking for the container I need, and through
docker exec _name_ sh -c "cd /var/lib/postgresql/data && tar cf /backup/postgres.tar ."
I get a dump. But this is not very beautiful, especially when a lot of containers are running.
Are there other ways?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nazar Mokrinsky, 2016-03-16
@furyon

Quite a working way. But you need to understand that without stopping postgresql, you can easily get inconsistent data in a way from which you will not recover anything. But in fact, I would rather create a separate container that would start with postgres-data and ./dump mounted and do only backups.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question