• Stars
    star
    247
  • Rank 164,117 (Top 4 %)
  • Language
    Shell
  • License
    MIT License
  • Created about 11 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Dockerfile that installs a mysql server

Circle CI Docker Repository on Quay.io

Table of Contents

Introduction

Dockerfile to build a MySQL container image which can be linked to other containers.

Contributing

If you find this image useful here's how you can help:

  • Send a Pull Request with your awesome new features and bug fixes
  • Help new users with Issues they may encounter
  • Support the development of this image with a donation

Reporting Issues

Docker is a relatively new project and is active being developed and tested by a thriving community of developers and testers and every release of docker features many enhancements and bugfixes.

Given the nature of the development and release cycle it is very important that you have the latest version of docker installed because any issue that you encounter might have already been fixed with a newer docker release.

For ubuntu users I suggest installing docker using docker's own package repository since the version of docker packaged in the ubuntu repositories are a little dated.

Here is the shortform of the installation of an updated version of docker on ubuntu.

sudo apt-get purge docker.io
curl -s https://get.docker.io/ubuntu/ | sudo sh
sudo apt-get update
sudo apt-get install lxc-docker

Fedora and RHEL/CentOS users should try disabling selinux with setenforce 0 and check if resolves the issue. If it does than there is not much that I can help you with. You can either stick with selinux disabled (not recommended by redhat) or switch to using ubuntu.

If using the latest docker version and/or disabling selinux does not fix the issue then please file a issue request on the issues page.

In your issue report please make sure you provide the following information:

  • The host distribution and release version.
  • Output of the docker version command
  • Output of the docker info command
  • The docker run command you used to run the image (mask out the sensitive bits).

Installation

Automated builds of the image are available on Dockerhub and is the recommended method of installation.

Note: Builds are also available on Quay.io

docker pull sameersbn/mysql:5.7.26-0

Alternately you can build the image yourself.

docker build -t sameersbn/mysql github.com/sameersbn/docker-mysql

Quick Start

Run the mysql image

docker run --name mysql -d sameersbn/mysql:5.7.26-0

You can access the mysql server as the root user using the following command:

docker run -it --rm --volumes-from=mysql sameersbn/mysql:5.7.26-0 mysql -uroot

Data Store

You should mount a volume at /var/lib/mysql.

SELinux users are also required to change the security context of the mount point so that it plays nicely with selinux.

mkdir -p /opt/mysql/data
sudo chcon -Rt svirt_sandbox_file_t /opt/mysql/data

The updated run command looks like this.

docker run --name mysql -d \
  -v /opt/mysql/data:/var/lib/mysql sameersbn/mysql:5.7.26-0

This will make sure that the data stored in the database is not lost when the image is stopped and started again.

Creating User and Database at Launch

NOTE

For this feature to work the debian-sys-maint user needs to exist. This user is automatically created when the database is installed for the first time (firstrun).

However if you were using this image before this feature was added, then it will not work as-is. You are required to create the debian-sys-maint user

docker run -it --rm --volumes-from=mysql sameersbn/mysql \
 mysql -uroot -e "GRANT ALL PRIVILEGES on *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '' WITH GRANT OPTION;"

To create a new database specify the database name in the DB_NAME variable. The following command creates a new database named dbname:

docker run --name mysql -d \
  -e 'DB_NAME=dbname' sameersbn/mysql:5.7.26-0

You may also specify a comma separated list of database names in the DB_NAME variable. The following command creates two new databases named dbname1 and dbname2

docker run --name mysql -d \
-e 'DB_NAME=dbname1,dbname2' sameersbn/mysql:5.7.26-0

To create a new user you should specify the DB_USER and DB_PASS variables.

docker run --name mysql -d \
  -e 'DB_USER=dbuser' -e 'DB_PASS=dbpass' -e 'DB_NAME=dbname' \
  sameersbn/mysql:5.7.26-0

The above command will create a user dbuser with the password dbpass and will also create a database named dbname. The dbuser user will have full/remote access to the database.

NOTE

  • If the DB_NAME is not specified, the user will not be created
  • If the user/database user already exists no changes are be made
  • If DB_PASS is not specified, an empty password will be set for the user

By default the new database will be created with the utf8 character set and utf8_unicode_ci collation. You may override these with the MYSQL_CHARSET and MYSQL_COLLATION variables.

docker run --name mysql -d \
  -e 'DB_USER=dbuser' -e 'DB_PASS=dbpass' -e 'DB_NAME=dbname' \
  -e 'MYSQL_CHARSET=utf8mb4' -e 'MYSQL_COLLATION=utf8_bin' \
  sameersbn/mysql:5.7.26-0

Creating remote user with privileged access

To create a remote user with privileged access, you need to specify the DB_REMOTE_ROOT_NAME and DB_REMOTE_ROOT_PASS variables, eg.

docker run --name mysql -d \
  -e 'DB_REMOTE_ROOT_NAME=root' -e 'DB_REMOTE_ROOT_PASS=secretpassword' \
  sameersbn/mysql:5.7.26-0

Optionally you can specify the DB_REMOTE_ROOT_HOST variable to define the address space within which remote access should be permitted. This defaults to 172.17.0.1 and should suffice for most cases.

Situations that would require you to override the default DB_REMOTE_ROOT_HOST setting are:

  • If you have changed the ip address of the docker0 interface
  • If you are using host networking, i.e. --net=host, etc.

Shell Access

For debugging and maintenance purposes you may want access the containers shell. If you are using docker version 1.3.0 or higher you can access a running containers shell using docker exec command.

docker exec -it mysql bash

If you are using an older version of docker, you can use the nsenter linux tool (part of the util-linux package) to access the container shell.

Some linux distros (e.g. ubuntu) use older versions of the util-linux which do not include the nsenter tool. To get around this @jpetazzo has created a nice docker image that allows you to install the nsenter utility and a helper script named docker-enter on these distros.

To install nsenter execute the following command on your host,

docker run --rm -v /usr/local/bin:/target jpetazzo/nsenter

Now you can access the container shell using the command

sudo docker-enter mysql

For more information refer https://github.com/jpetazzo/nsenter

Upgrading

To upgrade to newer releases, simply follow this 3 step upgrade procedure.

  • Step 1: Stop the currently running image
docker stop mysql
  • Step 2: Update the docker image.
docker pull sameersbn/mysql:5.7.26-0
  • Step 3: Start the image
docker run --name mysql -d [OPTIONS] sameersbn/mysql:5.7.26-0

More Repositories

1

docker-gitlab

Dockerized GitLab
Shell
7,893
star
2

docker-redmine

Docker Image for Redmine
Shell
1,255
star
3

docker-postgresql

Dockerfile to build a PostgreSQL container image which can be linked to other containers.
Shell
1,050
star
4

docker-bind

Dockerize BIND DNS server with webmin for DNS administration
Shell
913
star
5

docker-squid

Dockerfile to create a Docker container image for Squid proxy server
Shell
818
star
6

docker-browser-box

Dockerized google-chome and tor-browser with audio support via pulseaudio
Shell
574
star
7

docker-apt-cacher-ng

Dockerfile to create a Docker container image for Apt-Cacher NG
Shell
210
star
8

docker-gitlab-ci

Dockerfile to build a GitLab CI container image.
Shell
199
star
9

docker-redis

Dockerfile to create a Docker container image for Redis.
Shell
156
star
10

docker-gitlab-ci-multi-runner

Shell
145
star
11

docker-skype

Dockerized skype with voice and video call support
Shell
139
star
12

docker-gitlab-ci-runner

Dockerfile to build a base GitLab CI Runner container image.
Shell
98
star
13

docker-openfire

Dockerfile to create a Docker container image for Openfire.
Shell
81
star
14

docker-nginx

A Dockerfile that installs nginx (from source) with nginx-rtmp module support (php5 support can be added using the sameersbn/php5-fpm image)
Shell
76
star
15

docker-wowza

Dockerfile to containerize Wowza Streaming Engine
Shell
64
star
16

docker-mongodb

Dockerfile to build a MongoDb container image which can be linked to other containers.
Shell
47
star
17

docker-invoiceplane

Dockerfile to create a Docker container image for InvoicePlane
Shell
45
star
18

docker-owncloud

Experimental owncloud image for docker
Shell
34
star
19

docker-ubuntu

My Ubuntu boilerplate image that forms the base for my docker containers.
Makefile
33
star
20

docker-nextcloud

Shell
31
star
21

docker-runner-gitlab

A CI runner for gitlab-ce built on top of the https://github.com/sameersbn/docker-gitlab-ci-runner
Shell
27
star
22

docker-memcached

Dockerfile to build a memcached container image which can be linked to other containers.
Dockerfile
27
star
23

docker-extras

Helper scripts for everyday docker use.
Shell
19
star
24

docker-akaunting

Docker for Akaunting
Shell
19
star
25

docker-ffmpeg

Base your docker image on this image if you need a bleeding egde version of fffmpeg.
Shell
17
star
26

docker-laboard

Docker file to build a Laboard image
Shell
10
star
27

docker-php-fpm

Dockerfile to build a php-fpm container.
Dockerfile
8
star
28

docker-nodejs

Dockerfile to build a nodejs+express image with nodemon
Shell
7
star
29

docker-rygel

Dockerfile to build a Rygel DLNA/uPNP server docker image.
Makefile
7
star
30

docker-skypeforlinux

Dockerized Skype for Linux (alpha)
Shell
6
star
31

docker-mysql2psql

Dockerfile that packages mysql2psql and py-mysql2pqsql tools.
Makefile
6
star
32

docker-debian

debian jessie baseimage that packs a couple of extra packages.
Makefile
2
star