首页 > 解决方案 > Why edit contents of docker-compose.yml are not reflected?

问题描述

I want to use MySQL by using Docker.

I wrote the following DockerFile and docker-compose.yml.

Dockerfile

FROM mysql:8.0
RUN mkdir /var/log/mysql
RUN touch /var/log/mysql/mysqld.log

docker-compose.yml

version: '3'
services:
  dbserver:
    build: ./docker/mysql
    image: test-db:0.0.1
    restart: always
    environment:
      MYSQL_DATABASE: prototype
      MYSQL_USER: user
      MYSQL_PASSWORD: password
      MYSQL_ROOT_PASSWORD: rootpassword
    ports:
      - "3306:3306"
    volumes:
      - ./docker/mysql/initdb.d:/docker-entrypoint-initdb.d
      - ./docker/mysql/conf.d:/etc/mysql/conf.d
      - ./log/mysql:/var/log/mysql
      - ./docker/mysql/data:/var/lib/mysql
volumes:
  mysql-bd:
    driver: local

I succeeded build and could confirm the database.

Then I wanted to change the database name, so I edited a part of the yml file following.

Before

      MYSQL_DATABASE: prototype

After

      MYSQL_DATABASE: test_db

Then, I confirmed the database but its name was not changed.

I removed the MySQL container and tried again, but the result was not changed.

Why edit contents of docker-compose.yml are not reflected?

标签: mysqldockerdocker-composedockerfile

解决方案


您正在为数据库使用主机卷,这意味着数据库在容器重新启动之间保持不变。

...
volumes:
  ./docker/mysql/data:/var/lib/mysql
...

删除本地目录./docker/mysql/data并重新启动服务。将反映数据库更改。


推荐阅读