mysql - 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?
解决方案
您正在为数据库使用主机卷,这意味着数据库在容器重新启动之间保持不变。
...
volumes:
./docker/mysql/data:/var/lib/mysql
...
删除本地目录./docker/mysql/data
并重新启动服务。将反映数据库更改。
推荐阅读
- google-apps-script - .getRange 的 .setValue 更简单的方法,而不会丢失其他单元格中的公式
- javascript - 调用键盘时页脚上升
- python - web3.py swapExactTokensForTokens 交易失败
- swift - 将字符串转换为日期对象返回 nil
- javascript - React redux reducer 作为 UseEffect 依赖导致无限循环
- amazon-web-services - 如何防止 Terraform 用 CodeDeploy 替换 ECS 服务
- javascript - IF 语句中的 Javascript“NaN”
- firebase - Save way to create a Firestore document
- python - 按列表顺序替换值
- python - lxml etree cleanup_namespaces 返回 None 而不是清理的树