Running MySQL in a Docker container

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:

root@1bbeb34f3491:/# mysqld

140730 4:49:04 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.

140730 4:49:04 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.

140730 4:49:04 [Note] Plugin 'FEDERATED' is disabled.

mysqld: Table 'mysql.plugin' doesn't exist

140730 4:49:04 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.

140730 4:49:04 InnoDB: The InnoDB memory heap is disabled

140730 4:49:04 InnoDB: Mutexes and rw_locks use GCC atomic builtins

140730 4:49:04 InnoDB: Compressed tables use zlib 1.2.8

140730 4:49:04 InnoDB: Using Linux native AIO

140730 4:49:04 InnoDB: Initializing buffer pool, size = 128.0M

140730 4:49:04 InnoDB: Completed initialization of buffer pool

140730 4:49:04 InnoDB: highest supported file format is Barracuda.

140730 4:49:04 InnoDB: Waiting for the background threads to start

140730 4:49:05 InnoDB: 5.5.37 started; log sequence number 1595675

140730 4:49:05 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306

140730 4:49:05 [Note] - '0.0.0.0' resolves to '0.0.0.0';

140730 4:49:05 [Note] Server socket created on IP: '0.0.0.0'.

140730 4:49:05 [ERROR] Can't start server : Bind on unix socket: Permission denied

140730 4:49:05 [ERROR] Do you already have another mysqld server running on socket: /var/run/mysqld/mysqld.sock ?

140730 4:49:05 [ERROR] Aborting

140730 4:49:05 InnoDB: Starting shutdown... 140730 4:49:06 InnoDB: Shutdown completed; log sequence number 1595675 140730 4:49:06 [Note] mysqld: Shutdown complete

Addressing the errors

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

root@1bbeb34f3491:/# mysql_upgrade

Looking for 'mysql' as: mysql

Looking for 'mysqlcheck' as: mysqlcheck

FATAL ERROR: Upgrade failed

  • "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 but that doesn't work either.

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

EDIT If someone could create a set of instructions that creates one MySQL container and one linked container and works for them so I can give it a go.


Solution 1:

With sameersbn/mysql

I don't believe you can run it interactively.

docker run --name mysql -d sameersbn/mysql:latest

So you simply run it as a daemon, inspect the container to find the IP address like so:

docker inspect mysql | grep IPAddres

and then you can connect to mysql on that IP.