MySQL 如何在docker容器中启动mysql服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31918987/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to start mysql server in docker container
提问by Mark Taylor
I am creating docker container and base image is ubuntu:14.04. I have to start mysql server in that container and then I have to create databases and I have to give the permission to the users. Docker is new for me. I tried a lot but still whenever I go to that image and check for mysql server is running or not. Every time what I got is mysql server is stopped and my dbs are also not created. This is my dockerfile
我正在创建 docker 容器,基本映像是 ubuntu:14.04。我必须在该容器中启动 mysql 服务器,然后我必须创建数据库,并且必须向用户授予权限。Docker 对我来说是新的。我尝试了很多,但仍然是每当我转到该图像并检查 mysql 服务器是否正在运行时。每次我得到的是 mysql 服务器停止并且我的数据库也没有创建。这是我的 dockerfile
FROM ubuntu:14.04
MAINTAINER <name> <emailid>
RUN sudo apt-get update
RUN sudo apt-get install -y apache2 mysql-server libapache2-mod-auth-mysql php5-mysql php5 git
RUN sudo apt-get install -y vim
CMD sudo /usr/sbin/mysqld -u mysql
I tried a lot but i am not able to run mysql server in docker image.
我尝试了很多,但我无法在 docker 镜像中运行 mysql 服务器。
回答by 0x7d7b
Did you manually install it in your container?
您是否手动将其安装在容器中?
Why do you not simply use:
你为什么不简单地使用:
docker run -d --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=secret -e MYSQL_DATABASE=mySchema mysql:5
That would start a container named mysqlrunning a mysql daemon, setting the default root password to secret, creating a new schema called mySchemaand expose the MySQL port 3306 to clients so that they could connect.
这将启动一个名为mysql的容器,运行一个 mysql 守护进程,将默认 root 密码设置为secret,创建一个名为mySchema的新模式,并将 MySQL 端口 3306 公开给客户端,以便他们可以连接。
Then you could connect to that with any MySQL client using the root user with the specified password secretand create your tables within the created schema mySchema.
然后,您可以使用具有指定密码secret的 root 用户连接到任何 MySQL 客户端,并在创建的架构mySchema 中创建您的表。
回答by Sindhu
I had similar issue for ubuntu :14.04 while setting up druid cluster in the docker container, using CMD to start mysql fixed it for me.
在 docker 容器中设置德鲁伊集群时,我在 ubuntu :14.04 上遇到了类似的问题,使用 CMD 启动 mysql 为我修复了它。
CMD mysql start \
CMD mysql 启动 \
Druid related stuff
德鲁伊相关的东西
&& mysql stop