[英]docker compose - mysql - password
I have docker-compose file我有 docker-compose 文件
version: '3.5'
services:
db:
image: itaybeyder/mysql:2
# secrets:
# - MYSQL_ROOT_PASSWORD
hostname: mysql
container_name: mysql
environment:
MYSQL_ROOT_PASSWORD: run/secrets/MYSQL_ROOT_PASSWORD.txt
MYSQL_DATABASE: crud
networks:
- app
ports:
- "3306:3306"
command: --init-file /data/application/crud.sql
volumes:
- ./data/crud.sql:/data/application/crud.sql
- ./data/MYSQL_ROOT_PASSWORD.txt:/run/secrets/MYSQL_ROOT_PASSWORD.txt
networks:
app:
external: false
# secrets:
# MYSQL_ROOT_PASSWORD:
# external: true
and in the volume ( local folder in my computer ) i have password for mysql ROOT在卷中(我电脑中的本地文件夹)我有 mysql ROOT 的密码
volumes:
- ./data/MYSQL_ROOT_PASSWORD.txt:/run/secrets/MYSQL_ROOT_PASSWORD.txt
i'm trying to pass it to the env - MYSQL_ROOT_PASSWORD, but im getting error:我正在尝试将它传递给环境 - MYSQL_ROOT_PASSWORD,但我收到错误:
mysql | 2021-12-26 16:27:10+00:00 [ERROR] [Entrypoint]: Both MYSQL_ROOT_PASSWORD and MYSQL_ROOT_PASSWORD_FILE are set (but are exclusive)
when im using docker stack its working but i want to use it with docker-compose.当我使用docker 堆栈时,它可以工作,但我想将它与 docker-compose 一起使用。
MY QUESTION : how can i pass, password of the ROOT with the ENV我的问题:我怎样才能通过 ENV 的 ROOT 密码
environment: MYSQL_ROOT_PASSWORD环境:MYSQL_ROOT_PASSWORD
with file that will be sitting in the container himself,, ?文件将自己放在容器中,,? im coping file from the host to the container and i want him to read if from the local path , is it possible ?
我将文件从主机复制到容器,我希望他从本地路径读取,这可能吗?
other way , simplest, how can i transfer local password i have in the host to the ENV of MYSQL_ROOT_PASSWORD?其他方式,最简单,如何将主机中的本地密码传输到 MYSQL_ROOT_PASSWORD 的 ENV?
You can create a .env
file at same directory of your docker-compose.yaml
file.您可以在
docker-compose.yaml
文件的同一目录中创建一个.env
文件。
.env
: .env
:
MYSQL_ROOT_PASSWORD=SUPER_STRONG_PASSWORD
Then at your docker-compose.yaml
you can specify it like this:然后在你的
docker-compose.yaml
你可以这样指定它:
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
You can use docker-compose config
to check if your configuration was applied.您可以使用
docker-compose config
来检查您的配置是否已应用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.