本文介绍了在Docker容器中运行MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的最终目标是运行一个MySQL Docker容器(从公共注册表中读取tutum / mysql),然后将一个Gitlab Docker容器(比如sameersbn / gitlab)链接到两个容器都使用持久存储的容器。 >

但是,我被困在MySQL部分。每次尝试运行一个预先制作的MySQL Docker容器(mysql,tutum / mysql和sameersbn / mysql),如下所示,我得到以下输出。



步骤



这只是获取以下错误消息的一种方法


  1. docker.io pull tutum / mysql:最新

  2. docker.io run -it tutum / mysql bash

  3. 一旦附加到新容器,运行/run.sh(按照tutum / mysql dockerfile)

  4. 在这一点上等待MySQL服务启动的确认消息不断重复。

  5. 此时如果我取消/run.sh命令并自动启动MySQL,我将收到以下错误消息。 / li>

输出:

解决错误




  • 请运行mysql_upgrade创建它=>运行mysql_upgrade命令输出






  • 你已经有另一个mysqld服务器在套接字上运行=>不是。运行服务mysql stop什么也不做,运行ps不显示mysqld。运行ls -a / var / run / mysqld /表示套接字文件不存在。



无论哪个MySQL容器尝试,最终当我启动MySQL同样的错误信息出现。这几乎肯定意味着我的设置有问题,这使我感到困惑,因为我认为一个Docker容器,没有暴露的端口或永久存储,将被隔离系统Docker安装在哪里?



我也尝试运行一个带有-d标志的MySQL容器,然后运行一个链接到它的新的ubuntu 14.04容器(docker.io run -it -link mysql:mysql ubuntu:14.04 bash)。在Ubuntu容器上,我通过apt-get安装了mysql-client,并尝试连接到MYSQL_PORT_3306_TCP_ADDR中的IP地址上的MySQL容器,但这也不行。



同样的问题可能是我不明白Docker如何工作。如果是这种情况,有人可以创建一组步骤,使用Docker索引上的一个MySQL容器,然后将容器链接到可以连接的容器。这也有助于查看我的Docker安装是否有问题(或者是导致此问题的其他一些未知问题)。



我的主机系统正在运行Ubuntu 14.04,Docker是通过apt-get安装的,是0.9.1版。



我不太确定这个解释是什么,因为这个问题对我来说似乎很奇怪。如果有什么我错过了请问,我会为你添加。



谢谢,
JamesStewy

解决方案

这对我有用:

docker run -d -p 3306:3306 -e MYSQL_PASS =mypasstutum / mysql



不需要从bash运行脚本,不需要任何聪明的东西。


So my ultimate end goal is to run a MySQL Docker container (say tutum/mysql from the public registry) and then link a Gitlab Docker container (say sameersbn/gitlab) to it where both containers use persistent storage.

However, I am stuck on the MySQL part. Every time I try and run a pre-made MySQL Docker container (mysql, tutum/mysql and sameersbn/mysql) as outlined below, I get the below output.

Steps

This is just one way of getting to the error message below.

  1. docker.io pull tutum/mysql:latest
  2. docker.io run -it tutum/mysql bash
  3. Once attached to the new container run "/run.sh" (as per tutum/mysql dockerfile)
  4. At this point a "Waiting for confirmation of MySQL service startup" message constantly repeats.
  5. At this point if I cancel the "/run.sh" command and start MySQL myself I get the error message below.

Output:

Addressing the errors

  • "Please run mysql_upgrade to create it" => run mysql_upgrade command which outputs

  • "Do you already have another mysqld server running on socket" => Nope. Running service mysql stop does nothing and running ps doesn't show mysqld. Running ls -a /var/run/mysqld/ suggests that the socket file doesn't exist.

No matter which MySQL container I try, eventually when I start MySQL the same error message came up. This almost certainly means there is something wrong with my setup which confuses me because I thought a Docker container, with no exposed ports or persistent storage, would be isolated from the system Docker is installed on?

I have also tried running a MySQL container with the -d flag then running a fresh ubuntu 14.04 container (docker.io run -it --link mysql:mysql ubuntu:14.04 bash) linked to it. On the Ubuntu container I installed mysql-client through apt-get and tried to connect to the MySQL container on the ip address in MYSQL_PORT_3306_TCP_ADDR but that doesn't work either.

Equally the problem might be that I do not understand how Docker works. If this is the case, can someone create a set of steps that uses one of the MySQL containers on the Docker index and then link a container to it that can connect. This will also help to see whether there is something wrong with my Docker installation (or some other unknown problem that is causing this issue).

My host system is running Ubuntu 14.04 and Docker was installed through apt-get and is version 0.9.1.

I wasn't quite sure what to put in this explanation because the problem seems quite weird to me. If there is anything I have missed please ask and I will add it for you.

Thanks,JamesStewy

解决方案

This works for me: docker run -d -p 3306:3306 -e MYSQL_PASS="mypass" tutum/mysql

No need to run the script from bash, no need for anything clever.

这篇关于在Docker容器中运行MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-20 22:50
查看更多