Docker MySQL停止并退出(1)

时间:2018-10-13 06:15:28

标签: mysql docker

我试图在Docker容器中启动MySql。但是,它停止并退出了代码exit(1)。这是我的运行方式:

docker run --name demo-db -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d mysql:latest --mount type=bind,source=$(pwd),target=/var/lib/mysql

这是容器的日志

Initializing database
2018-10-12T17:50:42.694183Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2018-10-12T17:50:42.694277Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.12) initializing of server in progress as process 31
mbind: Operation not permitted
mbind: Operation not permitted
mbind: Operation not permitted
mbind: Operation not permitted
2018-10-12T17:51:10.497527Z 0 [ERROR] [MY-011071] [Server] unknown option '--mount'
2018-10-12T17:51:10.497543Z 0 [Warning] [MY-010952] [Server] The privilege system failed to initialize correctly. If you have upgraded your server, make sure you're executing mysql_upgrade to correct the issue.
2018-10-12T17:51:10.497551Z 0 [ERROR] [MY-010119] [Server] Aborting
2018-10-12T17:51:14.130241Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.12)  MySQL Community Server - GPL.

请帮助我...

2 个答案:

答案 0 :(得分:0)

可能会有更好的答案,我过去也将Docker用于MySQL,但是已经有一段时间了。

从分离式容器开始:

docker run -v $PWD:/var/lib/mysql --name demo-db -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d mysql:latest

然后像这样附加到它:

docker run -i -t demo-db /bin/bash

关于pwd使用的注意事项:

无需使用pwd命令,只需获取shell变量$PWD。当您执行foo=$(pwd)有点过分时,b / c实际上是在子shell中运行pwd命令以返回$PWD

答案 1 :(得分:0)

docker run命令的语法基本上是

docker run <docker run options> IMAGE <command and arguments>

因此,当您运行时:

docker run \
  --name demo-db -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d \
  mysql:latest \
  --mount type=bind,source=$(pwd),target=/var/lib/mysql

--mount选项位于图像名称之后 ,因此将其作为参数传递给容器。将这个选项移到之前 mysql:latest,您将被设置。