3

We have a Rails app with MySQL as DB. The db part of docker-compose.yml looks like

  db:
    image: mysql
    env_file:
      - ma.env
    volumes:
      - ./dump-db:/docker-entrypoint-initdb.d
      - ./my.cnf:/etc/mysql/my.cnf
    restart: always
    ports:
      - "3306:3306"
    environment:
            - MYSQL_HOST=

and under ./dump-db folder there actually is an sql-dump of our db.

Problem is, we need to have that exact dump loaded each and every time docker-compose up is run. MySQL docker image works in such a way, that it stores it's data on host machine and therefore your db-service is not stateless.

What we need is that db service discarded all changes done within docker-compose up previous run and fresh-started with that exact dump.

2
  • 1
    Make your own container derived from the mysql official. Or roll your own custom mysql. Or have your rails app bootstrap mysql. Or make a new container that only bootstraps your mysql. Or use rails seeds. Or... Commented Sep 29, 2016 at 18:23
  • I think this is write. Customize the image to do what you want (not use a volume for the data store). Commented Sep 30, 2016 at 16:32

2 Answers 2

3

SOLVED

actually, ideas above gave me some insight to RTM and here goes

  • Get your own MySQL Dockerfile
  • Remove the VOLUME line from it, where it mentions that /var/lib/mysql should be mounted on host.
  • docker-compose up --force-recreate db
Sign up to request clarification or add additional context in comments.

Comments

-1

If you don't want to keep the data each time that you execute the docker-compose up you have to remove the volumes created by the execution of this command.

To achieve that you can execute the following command, that will remove the db service with the volumes declared in the volumes section.

docker-compose down -v db

2 Comments

thanks! but is there a way to convince docker-compose to automatically kill volumes?
That command is wrong. down doesn't take positional arguments. You can do docker-compose down -v or docker-compose rm -v db.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.