How can I stop a MySQL docker container which populates a volume after database initialisation is complete?

微笑、不失礼 提交于 2019-12-24 21:49:35

问题


I have a docker-compose.yml file with the following:

 populated_db:
        container_name: populated_db
        restart: always
        image: mysql
        volumes:
            - ./test_database.sql:/docker-entrypoint-initdb.d/a.sql
            - populated_test_db:/var/lib/mysql
        ports:
            - "33061:3306"
        environment:
            MYSQL_RANDOM_ROOT_PASSWORD: "true"
            MYSQL_DATABASE: aaaa
            MYSQL_USER: aaaa
            MYSQL_PASSWORD: aaaa
db:
    container_name: db
    image: mysql
    ports:
        - "33060:3306"
    volumes:
        - type: volume
          source: populated_test_db
          target: /var/lib/mysql
          volume:
            nocopy: false
    restart: always
    environment:
        MYSQL_RANDOM_ROOT_PASSWORD: "true"
        MYSQL_DATABASE: aaaa
        MYSQL_USER: aaaa
        MYSQL_PASSWORD: aaaa
    depends_on:
        - populated_db

volumes:
    populated_test_db:

The populated_db container successfully starts and populates the database with the contents of test_database.sql. However, once it has done that, the db container starts and tries to use populated_test_db as its /var/lib/mysql, causing the following error:

Unable to lock ./ibdata1 error: 11
Check that you do not already have another mysqld process using the same InnoDB data or log files.

Presumably this is because the populated_db container is still running. How can I stop it running once it has populated the volume, so the db container can use the populated volume?

来源:https://stackoverflow.com/questions/52582639/how-can-i-stop-a-mysql-docker-container-which-populates-a-volume-after-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!