我怎样才能阻止一个MySQL泊坞窗容器,填充卷后数据库初始化结束?(How can I stop a

2019-10-29 18:15发布

我有以下的码头工人,compose.yml文件:

 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:

该populated_db容器成功启动并填充test_database.sql的内容数据库。 但是,一旦这样做了,那么数据库容器,并开始尝试使用populated_test_db作为其在/ var / lib中/ MySQL的,引起以下错误:

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

这大概是因为populated_db容器仍在运行。 我怎样才能阻止它运行一旦填充体积,所以分贝容器可以用填充量?

文章来源: How can I stop a MySQL docker container which populates a volume after database initialisation is complete?