数据库初始化完成后,如何停止填充卷的MySQL docker容器?

时间:2018-09-30 22:20:59

标签: mysql docker testing docker-compose

我有一个docker-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的内容填充数据库。但是,一旦这样做,db容器就会启动并尝试将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容器仍在运行。填充卷后如何停止它的运行,以便db容器可以使用填充的卷?

0 个答案:

没有答案