我试图在docker容器中调出我的MySql。但是,它在代码退出(1)的情况下停止了。下面是我的运行方式:
Docker运行--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.
请帮帮我...
更好的答案可能随之而来,我曾经也使用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
。
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
之前,您将被设置。