我尝试按照https://docs.docker.com/get-started/part3/上的说明进行操作,但将其更改为单个节点MariaDB数据库。我正在使用看起来像这样的docker-compose.yml
文件......
version: "3"
services:
database:
image: mariadb:latest
environment:
MYSQL_DATABASE: jeesample
MYSQL_USER: jeeuser
MYSQL_PASSWORD: password
networks:
- webnet
ports:
- "3307:3306"
networks:
webnet:
然后我用
开始docker stack deploy -c docker-compose.yml jeesample
然而,当我查看docker stack ps jeesample
时,我得到以下内容:
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
9yjyzmi86aqm jeesample_database.1 mariadb:latest moby Running Running less than a second ago
gqamjzc2u1fw \_ jeesample_database.1 mariadb:latest moby Shutdown Failed 6 seconds ago "task: non-zero exit (1)"
615zc8s0rts1 \_ jeesample_database.1 mariadb:latest moby Shutdown Failed 18 seconds ago "task: non-zero exit (1)"
pod5ldwn6p6v \_ jeesample_database.1 mariadb:latest moby Shutdown Failed 27 seconds ago "task: non-zero exit (1)"
ma1gkri9os14 \_ jeesample_database.1 mariadb:latest moby Shutdown Failed 37 seconds ago "task: non-zero exit (1)"
尝试使用jdbc:mariadb://localhost:3307/jeesample
从本地计算机上的SQL客户端连接到它失败,因为我无法连接
答案 0 :(得分:2)
诊断此问题的一种方法是查看日志。要获取日志,请执行docker ps
以获取容器列表,然后docker logs -f <container ID>
以获取日志结果。由于它是在docker-compose上,容器可能会在一段时间后消失,因此-f
选项会保持连接直到它终止。
要解决日志说root用户需要密码的问题,我只需要添加
MYSQL_RANDOM_ROOT_PASSWORD: "true"
虽然还有其他选择
MYSQL_ROOT_PASSWORD: "blah" // visible on source
MYSQL_ALLOW_EMPTY_PASSWORD: "yes" // not recommended