Git Product home page Git Product logo

docker-mysql-old's Introduction

Table of Contents

Installation

Pull the latest version of the image from the docker index. This is the recommended method of installation as it is easier to update image in the future. These builds are performed by the Docker Trusted Build service.

docker pull zaraki673/mysql:latest

Alternately you can build the image yourself.

git clone https://github.com/zaraki673/docker-mysql.git
cd docker-mysql
docker build -t="$USER/mysql" .

Quick Start

Run the mysql image

docker run -name mysql -d zaraki673/mysql:latest

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

docker run -it --rm --volumes-from=mysql zaraki673/mysql mysql -u root

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 zaraki673/mysql:latest

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 zaraki673/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' zaraki673/mysql:latest

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' \
  zaraki673/mysql:latest

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

Shell Access

For debugging and maintenance purposes you may want access the container shell. Since the container does not allow interactive login over the SSH protocol, 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 the nsenter tool on your host execute the following command.

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

Another tool named nsinit can also be used for the same purpose. Please refer https://jpetazzo.github.io/2014/03/23/lxc-attach-nsinit-nsenter-docker-0-9/ for more information.

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 zaraki673/mysql:latest
  • Step 3: Start the image
docker run -name mysql -d [OPTIONS] zaraki673/mysql:latest

docker-mysql-old's People

Contributors

fb avatar frank-dspeed avatar zaraki673 avatar

Watchers

 avatar  avatar  avatar

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.