Git Product home page Git Product logo

docker-mariadb's Introduction

docker-mariadb

A Dockerfile that produces a container that will run MariaDB 5.5, a drop-in replacement for MySQL.

Image Creation

This example creates the image with the tag paintedfox/mariadb, but you can change this to use your own username.

$ docker build -t="paintedfox/mariadb" .

Alternately, you can run the following if you have make installed...

$ make

You can also specify a custom docker username like so:

$ make DOCKER_USER=paintedfox

Container Creation / Running

The MariaDB server is configured to store data in /data inside the container. You can map the container's /data volume to a volume on the host so the data becomes independant of the running container.

This example uses /tmp/mariadb to store the MariaDB data, but you can modify this to your needs.

When the container runs, it creates a superuser with a random password. You can set the username and password for the superuser by setting the container's environment variables. This lets you discover the username and password of the superuser from within a linked container or from the output of docker inspect mariadb.

$ mkdir -p /tmp/mariadb
$ docker run -d -name="mariadb" \
             -p 127.0.0.1:3306:3306 \
             -v /tmp/mariadb:/data \
             -e USER="super" \
             -e PASS="$(pwgen -s -1 16)" \
             paintedfox/mariadb

Alternately, you can run the following if you have make installed...

$ make run

You can also specify a custom port to bind to on the host, a custom data directory, and the superuser username and password on the host like so:

$ sudo mkdir -p /srv/docker/mariadb
$ make run PORT=127.0.0.1:3306 \
           DATA_DIR=/srv/docker/mariadb \
           USER=super \
           PASS=$(pwgen -s -1 16)

Connecting to the Database

To connect to the MariaDB server, you will need to make sure you have a client. You can install the mysql-client on your host machine by running the following (Ubuntu 12.04LTS):

$ sudo apt-get install mysql-client

As part of the startup for MariaDB, the container will generate a random password for the superuser. To view the login in run docker logs <container_name> like so:

$ docker logs mariadb
MARIADB_USER=super
MARIADB_PASS=FzNQiroBkTHLX7y4
MARIADB_DATA_DIR=/data
Starting MariaDB...
140103 20:33:49 mysqld_safe Logging to '/data/mysql.log'.
140103 20:33:49 mysqld_safe Starting mysqld daemon with databases from /data

Then you can connect to the MariaDB server from the host with the following command:

$ mysql -u super --password=FzNQiroBkTHLX7y4 --protocol=tcp

Linking with the Database Container

You can link a container to the database container. You may want to do this to keep web application processes that need to connect to the database in a separate container.

To demonstrate this, we can spin up a new container like so:

$ docker run -t -i -link mariadb:db ubuntu bash

This assumes you're already running the database container with the name mariadb. The -link mariadb:db will give the linked container the alias db inside of the new container.

From the new container you can connect to the database by running the following commands:

$ apt-get install -y mysql-client
$ mysql -u "$DB_ENV_USER" --password="$DB_ENV_PASS" -h "$DB_PORT_3306_TCP_ADDR" -P "$DB_PORT_3306_TCP_PORT"

If you ran the mariadb container with the flags -e USER=<user> and -e PASS=<pass>, then the linked container should have these variables available in its environment. Since we aliased the database container with the name db, the environment variables from the database container are copied into the linked container with the prefix DB_ENV_.

docker-mariadb's People

Contributors

heichblatt avatar niclashoyer avatar painted-fox avatar renato-zannon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-mariadb's Issues

Container fails to reinitialize on docker stop + start or host reboot

The container will fail to reinitialize and run MariaDB when you restart the container with a docker stop && docker start. It will also fail to reinitialize when you reboot the host machine.

I'm seeing this on a Digital Ocean droplet running Ubuntu 13.10 (64 bit).

Running docker logs mariadb shows:

MARIADB_SUPER_USER=super
MARIADB_SUPER_PASS=ENgLS9rQ2rQgEYKj
MARIADB_DATA_DIR=/data
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)

Strategy for MariaDB 10.00

Hi! I wanted to discuss the best strategy for supporting MariaDB 10 (which now is the current stable)

It would be easy to simply change the repository and call it a day, but I don't think it is 100% backwards compatible with MariaDB 5.5 - plus it is necessary to run mysql_upgrade after changing versions.

What do you think is the best strategy then? Having two images (potentially in another repo)?

Can't connect from other docker container

If I try to connect from another docker container I get

SQLSTATE[HY000] [1130] Host '172.17.0.4' is not allowed to connect to this MariaDB server

I see that there is the following in first_run.sh:

CREATE USER '$USER'@'%' IDENTIFIED BY '$PASS';
GRANT ALL PRIVILEGES ON *.* TO '$USER'@'%' WITH GRANT OPTION;

so it should be working. Any idea why I get this error? Is there something I could check?

EDIT:
Using docker logs I get:

MARIADB_USER=super
MARIADB_PASS=LlEZm86IxY0SXLNt
MARIADB_DATA_DIR=/data
Initializing MariaDB at /data
Starting MariaDB...
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
140306 22:26:33 mysqld_safe Logging to '/data/mysql.log'.
140306 22:26:33 mysqld_safe Starting mysqld daemon with databases from /data

Maybe the error in between is the problem?

The container launches multiple mysqld processes in a loop

I have multiple problems when mapping this to another port than the default 3306. I'm using the 3307 port instead.
When I do this container starts multiple processes and won't allow logging in.
$ mysql -u super --password=J8s0hY0d6QJsOfF0 --protocol=tcp --port=3307
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.