Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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

like image 439
JamesStewy Avatar asked Jul 31 '14 22:07

JamesStewy


People also ask

How do I create a MySQL database in a Docker container?

Learn to set up and run Docker containers for databasesCreate a Docker Compose YAML file for a MySQL Docker container. Connect to the MySQL database, running on a container, using various methods. Create and run multiple versions of MySQL in Docker containers.

Can you put a database in a Docker container?

You can use Docker to run a database in a container as if it were a remote server, and test how your application interacts with it. This tutorial describes how to run a Docker container with a PostgreSQL server and connect to it using IntelliJ IDEA.

Is Docker good for database?

If you're working on a small project, and are deploying to a single machine, it's completely okay to run your database in a Docker container. Be sure to mount a volume to make the data persistent, and have backup processes in place. Try to restore them every once in a while to make sure your backups are any good.


1 Answers

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.

like image 117
qwertyboy Avatar answered Oct 21 '22 14:10

qwertyboy