简体   繁体   中英

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?

You are using a host volume for your database, meaning that the databases are persisted between containers restarts.

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

Delete the local directory ./docker/mysql/data and restart your services. The database change will be reflected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM