Docker installation mysql database tutorial, dockermysql Database

Source: Internet
Author: User
Tags docker ps docker hub docker run

Docker installation mysql database tutorial, dockermysql Database

Install MySQL using Docker

Search for mysql images on Docker Hub

runoob@runoob:/mysql$ docker search mysqlNAME                     DESCRIPTION                                     STARS     OFFICIAL   AUTOMATEDmysql                    MySQL is a widely used, open-source relati...   2529      [OK]       mysql/mysql-server       Optimized MySQL Server Docker images. Crea...   161                  [OK]centurylink/mysql        Image containing mysql. Optimized to be li...   45                   [OK]sameersbn/mysql                                                          36                   [OK]google/mysql             MySQL server for Google Compute Engine          16                   [OK]appcontainers/mysql      Centos/Debian Based Customizable MySQL Con...   8                    [OK]marvambass/mysql         MySQL Server based on Ubuntu 14.04              6                    [OK]drupaldocker/mysql       MySQL for Drupal                                2                    [OK]azukiapp/mysql           Docker image to run MySQL by Azuki - http:...   2                    [OK]...

Here we pull the official image with the tag 5.7

runoob@runoob:~/mysql$ docker pull mysql:5.7

After the download is complete, we can find the image with the REPOSITORY of mysql and the label of 5.7 in the local image list.

Use a mysql image to run a container
runoob@runoob:~/mysql$ docker run -p 3306:3306 --name mymysql -v $PWD/conf/my.cnf:/etc/mysql/my.cnf -v $PWD/logs:/logs -v $PWD/data:/mysql_data -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.621cb89213c93d805c5bacf1028a0da7b5c5852761ba81327e6b99bb3ea89930erunoob@runoob:~/mysql$ 

Docker run -- name mysql5.7-p 3306: 3306-v/usr/mysql/conf/my. cnf:/conf/mysql/my. cnf-v/usr/mysql/logs:/logs/mysql-v/usr/mysql/data:/data/mysql-e MYSQL_ROOT_PASSWORD = 123456-d mysql: 5.7

Command description:

-P 3306: 3306: Map port 3306 of the container to port 3306 of the host.

-V $ PWD/conf/my. cnf:/etc/mysql/my. cnf: Run conf/my. the/etc/mysql/my. cnf

-V $ PWD/logs: mount the logs directory under the current directory of the host to the/logs directory of the container

-V $ PWD/data:/mysql_data: mount the data directory under the current directory of the host to/mysql_data of the container

-E MYSQL_ROOT_PASSWORD = 123456: initializes the password of the root user.

View container startup status
runoob@runoob:~/mysql$ docker ps CONTAINER ID    IMAGE         COMMAND                  ...  PORTS                    NAMES21cb89213c93    mysql:5.7    "docker-entrypoint.sh"    ...  0.0.0.0:3306->3306/tcp   mymysql
Docker deletes an image

1. query image docker images

Now you want to delete the first image with the ID 99f85991949f.

We can see from the above that the container with the ID of 67 *** needs to be stopped first.

2. query container docker ps-

Stop the container before deleting it.

Docker stop 4b3e40cba75f

3. First Delete the container docker rm4b3e40cba75f

As shown above, the container has been deleted.

4. Delete the image docker rmi bd1_dc46369

5. Force Delete image docker rmi-f bd1_dc46369 not recommended

Note:

1. Ensure that the container is stopped before deletion.

2. Note that the commands for deleting images and containers are different. Docker rmi ID, where the container (rm) and image (rmi)

3. In order, you need to delete the container first.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.