Public | Automated Build

Last pushed: 2 years ago
Short Description
Short description is empty for this repo.
Full Description

tutum-docker-mysql

Base docker image to run a MySQL database server

Usage

To create the image tutum/mysql, execute the following command on the tutum-mysql folder:

docker build -t tutum/mysql .

To run the image and bind to port 3306:

docker run -d -p 3306:3306 tutum/mysql

To run the image and bind to port 3306 and specify password for SSH:

docker run -d -p 3306:3306 -p 2222:22 -e ROOT_PASS="root_password" tutum/mysql    

Now you can log in ssh -p 2222 root@localhost

The first time that you run your container, a new user admin with all privileges
will be created in MySQL with a random password. To get the password, check the logs
of the container by running:

docker logs <CONTAINER_ID>

You will see an output like the following:

========================================================================
You can now connect to this MySQL Server using:

    mysql -uadmin -p47nnf4FweaKu -h<host> -P<port>

Please remember to change the above password as soon as possible!
MySQL user 'root' has no password but only allows local connections
========================================================================

In this case, 47nnf4FweaKu is the password allocated to the admin user.

Remember that the root user has no password but it's only accesible from within the container.

You can now test your deployment:

mysql -uadmin -p

Done!

Setting a specific password for the admin account

If you want to use a preset password instead of a random generated one, you can
set the environment variable MYSQL_PASS to your specific password when running the container:

docker run -d -p 3306:3306 -e MYSQL_PASS="mypass" tutum/mysql

You can now test your deployment:

mysql -uadmin -p"mypass"

Mounting the database file volume

In order to persist the database data, you can mount a local folder from the host
on the container to store the database files. To do so:

docker run -d -v /path/in/host:/var/lib/mysql tutum/mysql /bin/bash -c "/usr/bin/mysql_install_db"

This will mount the local folder /path/in/host inside the docker in /var/lib/mysql (where MySQL will store the database files by default). mysql_install_db creates the initial database structure.

Remember that this will mean that your host must have /path/in/host available when you run your docker image!

After this you can start your mysql image but this time using /path/in/host as the database folder:

docker run -d -p 3306:3306 -v /path/in/host:/var/lib/mysql tutum/mysql

If you don't want to create an admin user or the admin user has been created in the database file volume, you can set MYSQL_ADMIN_CREATED (any value will work) to skip the admin user creation:

docker run -d -p 3306:3306 -v /path/in/host:/var/lib/mysql -e MYSQL_ADMIN_CREATED=True tutum/mysql

Migrating an existing MySQL Server

In order to migrate your current MySQL server, perform the following commands from your current server:

To dump your databases structure:

mysqldump -u<user> -p --opt -d -B <database name(s)> > /tmp/dbserver_schema.sql

To dump your database data:

mysqldump -u<user> -p --quick --single-transaction -t -n -B <database name(s)> > /tmp/dbserver_data.sql

To import a SQL backup which is stored for example in the folder /tmp in the host, run the following:

sudo docker run -d -v /tmp:/tmp tutum/mysql /bin/bash -c "/import_sql.sh <rootpassword> /tmp/<dump.sql>")

Where <rootpassword> is the root password set earlier and <dump.sql> is the name of the SQL file to be imported.

Environment variables

MYSQL_PASS: Set a specific password for the admin account.

MYSQL_ADMIN_CREATED: When setting this environment to any value, MySQL container will NOT create admin user and its password.

ROOT_PASS: Set a specific password for the root system account.

Docker Pull Command
Owner
webdizz
Source Repository

Comments (0)