{"id":16540548,"url":"https://github.com/sameersbn/docker-mysql","last_synced_at":"2025-04-06T19:12:36.231Z","repository":{"id":11020416,"uuid":"13349500","full_name":"sameersbn/docker-mysql","owner":"sameersbn","description":"A Dockerfile that installs a mysql server","archived":false,"fork":false,"pushed_at":"2019-07-06T07:45:09.000Z","size":125,"stargazers_count":248,"open_issues_count":11,"forks_count":173,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-30T17:12:02.386Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sameersbn.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-10-05T17:41:03.000Z","updated_at":"2025-03-22T19:27:24.000Z","dependencies_parsed_at":"2022-09-06T07:30:21.996Z","dependency_job_id":null,"html_url":"https://github.com/sameersbn/docker-mysql","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sameersbn%2Fdocker-mysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sameersbn%2Fdocker-mysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sameersbn%2Fdocker-mysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sameersbn%2Fdocker-mysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sameersbn","download_url":"https://codeload.github.com/sameersbn/docker-mysql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247535519,"owners_count":20954576,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T18:52:44.592Z","updated_at":"2025-04-06T19:12:36.212Z","avatar_url":"https://github.com/sameersbn.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Circle CI](https://circleci.com/gh/sameersbn/docker-mysql.svg?style=svg)](https://circleci.com/gh/sameersbn/docker-mysql) [![Docker Repository on Quay.io](https://quay.io/repository/sameersbn/mysql/status \"Docker Repository on Quay.io\")](https://quay.io/repository/sameersbn/mysql)\n\n# Table of Contents\n\n- [Introduction](#introduction)\n- [Contributing](#contributing)\n- [Changelog](Changelog.md)\n- [Reporting Issues](#reporting-issues)\n- [Installation](#installation)\n- [Quick Start](#quick-start)\n- [Data Store](#data-store)\n- [Creating User and Database at Launch](#creating-user-and-database-at-launch)\n- [Creating remote user with privileged access](#creating-remote-user-with-privileged-access)\n- [Shell Access](#shell-access)\n- [Upgrading](#upgrading)\n\n# Introduction\n\nDockerfile to build a MySQL container image which can be linked to other containers.\n\n# Contributing\n\nIf you find this image useful here's how you can help:\n\n- Send a Pull Request with your awesome new features and bug fixes\n- Help new users with [Issues](https://github.com/sameersbn/docker-mysql/issues) they may encounter\n- Support the development of this image with a [donation](http://www.damagehead.com/donate/)\n\n# Reporting Issues\n\nDocker 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.\n\nGiven 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.\n\nFor ubuntu users I suggest [installing docker](https://docs.docker.com/installation/ubuntulinux/) using docker's own package repository since the version of docker packaged in the ubuntu repositories are a little dated.\n\nHere is the shortform of the installation of an updated version of docker on ubuntu.\n\n```bash\nsudo apt-get purge docker.io\ncurl -s https://get.docker.io/ubuntu/ | sudo sh\nsudo apt-get update\nsudo apt-get install lxc-docker\n```\n\nFedora 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.\n\nIf using the latest docker version and/or disabling selinux does not fix the issue then please file a issue request on the [issues](https://github.com/sameersbn/docker-mysql/issues) page.\n\nIn your issue report please make sure you provide the following information:\n\n- The host distribution and release version.\n- Output of the `docker version` command\n- Output of the `docker info` command\n- The `docker run` command you used to run the image (mask out the sensitive bits).\n\n# Installation\n\nAutomated builds of the image are available on [Dockerhub](https://hub.docker.com/r/sameersbn/mysql) and is the recommended method of installation.\n\n\u003e **Note**: Builds are also available on [Quay.io](https://quay.io/repository/sameersbn/mysql)\n\n```bash\ndocker pull sameersbn/mysql:5.7.26-0\n```\n\nAlternately you can build the image yourself.\n\n```bash\ndocker build -t sameersbn/mysql github.com/sameersbn/docker-mysql\n```\n\n# Quick Start\n\nRun the mysql image\n\n```bash\ndocker run --name mysql -d sameersbn/mysql:5.7.26-0\n```\n\nYou can access the mysql server as the root user using the following command:\n\n```bash\ndocker run -it --rm --volumes-from=mysql sameersbn/mysql:5.7.26-0 mysql -uroot\n```\n\n# Data Store\n\nYou should mount a volume at `/var/lib/mysql`.\n\nSELinux users are also required to change the security context of the mount point so that it plays nicely with selinux.\n\n```bash\nmkdir -p /opt/mysql/data\nsudo chcon -Rt svirt_sandbox_file_t /opt/mysql/data\n```\n\nThe updated run command looks like this.\n\n```\ndocker run --name mysql -d \\\n  -v /opt/mysql/data:/var/lib/mysql sameersbn/mysql:5.7.26-0\n```\n\nThis will make sure that the data stored in the database is not lost when the image is stopped and started again.\n\n# Creating User and Database at Launch\n\n\u003e **NOTE**\n\u003e\n\u003e 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).\n\u003e\n\u003e 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\n\u003e\n\u003e```bash\n\u003edocker run -it --rm --volumes-from=mysql sameersbn/mysql \\\n\u003e  mysql -uroot -e \"GRANT ALL PRIVILEGES on *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '' WITH GRANT OPTION;\"\n\u003e```\n\nTo create a new database specify the database name in the `DB_NAME` variable. The following command creates a new database named *dbname*:\n\n```bash\ndocker run --name mysql -d \\\n  -e 'DB_NAME=dbname' sameersbn/mysql:5.7.26-0\n```\n\nYou 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*\n\n```bash\ndocker run --name mysql -d \\\n-e 'DB_NAME=dbname1,dbname2' sameersbn/mysql:5.7.26-0\n```\n\nTo create a new user you should specify the `DB_USER` and `DB_PASS` variables.\n\n```bash\ndocker run --name mysql -d \\\n  -e 'DB_USER=dbuser' -e 'DB_PASS=dbpass' -e 'DB_NAME=dbname' \\\n  sameersbn/mysql:5.7.26-0\n```\n\nThe 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.\n\n**NOTE**\n- If the `DB_NAME` is not specified, the user will not be created\n- If the user/database user already exists no changes are be made\n- If `DB_PASS` is not specified, an empty password will be set for the user\n\nBy 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.\n\n```bash\ndocker run --name mysql -d \\\n  -e 'DB_USER=dbuser' -e 'DB_PASS=dbpass' -e 'DB_NAME=dbname' \\\n  -e 'MYSQL_CHARSET=utf8mb4' -e 'MYSQL_COLLATION=utf8_bin' \\\n  sameersbn/mysql:5.7.26-0\n```\n\n# Creating remote user with privileged access\n\nTo create a remote user with privileged access, you need to specify the `DB_REMOTE_ROOT_NAME` and `DB_REMOTE_ROOT_PASS` variables, eg.\n\n```bash\ndocker run --name mysql -d \\\n  -e 'DB_REMOTE_ROOT_NAME=root' -e 'DB_REMOTE_ROOT_PASS=secretpassword' \\\n  sameersbn/mysql:5.7.26-0\n```\n\nOptionally 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.\n\nSituations that would require you to override the default `DB_REMOTE_ROOT_HOST` setting are:\n\n- If you have changed the ip address of the `docker0` interface\n- If you are using host networking, i.e. `--net=host`, etc.\n\n# Shell Access\n\nFor 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.\n\n```bash\ndocker exec -it mysql bash\n```\n\nIf you are using an older version of docker, you can use the [nsenter](http://man7.org/linux/man-pages/man1/nsenter.1.html) linux tool (part of the util-linux package) to access the container shell.\n\nSome 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.\n\nTo install `nsenter` execute the following command on your host,\n\n```bash\ndocker run --rm -v /usr/local/bin:/target jpetazzo/nsenter\n```\n\nNow you can access the container shell using the command\n\n```bash\nsudo docker-enter mysql\n```\n\nFor more information refer https://github.com/jpetazzo/nsenter\n\n# Upgrading\n\nTo upgrade to newer releases, simply follow this 3 step upgrade procedure.\n\n- **Step 1**: Stop the currently running image\n\n```bash\ndocker stop mysql\n```\n\n- **Step 2**: Update the docker image.\n\n```bash\ndocker pull sameersbn/mysql:5.7.26-0\n```\n\n- **Step 3**: Start the image\n\n```bash\ndocker run --name mysql -d [OPTIONS] sameersbn/mysql:5.7.26-0\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsameersbn%2Fdocker-mysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsameersbn%2Fdocker-mysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsameersbn%2Fdocker-mysql/lists"}