Docker learn to install MySQL

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

1. Retrieving MySQL images from Docker

Instructions:

Docker search MySQL
2. Image download

Instructions:

Docker Pull mysql:5.7.19
3. View the local mirror list

Instructions:

Docker images
#修改镜像名称

Docker tag mysql:5.7.19 mysql:5.7
4. Create a container based on the image
[Email protected]~]$ Docker create-it mysql:5.762c975b37ad25b03914eb61e05088019f37ff9cb049a682ac02f20fac1761a4d
Note: Do not create a direct 5th item to start MySQL run
5. Set MySQL docker image to run automatically

Instructions:

Docker run--restart=always--name mysql5.7-p 3306:3306-v/my/mysql/datadir:/var/lib/mysql-e MYSQL_ROOT_PASSWORD= 123456-d mysql:5.7

A nickname for the--name container.
-P port mapping. The format is the port of the host: the Port of the container. 2 of them are 3306, so it's 3,306:3,306.
-e Sets the environment variables for the container. -e mysql_root_password=123456 The password for the ROOT of MYSQL is 123456
-D Use the mirror package name, which can be viewed via Docker images
-V Mounts the/my/mysql/datadir in the current directory of the host to the/var/lib/mysql of the container;

Restart=always, tell Docker that this container is going to start automatically.

6. Go to MySQL terminal
[[Email protected]~]$ docker pscontainer ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    names2a7a85124400        mysql:5.7           "/entrypoint.sh my ..."   9 seconds ago up       8 seconds        0.0.0.0:3306- >3306/tcp   mysqlserver188099665d1e        ubuntu:latest       "/bin/bash" at              hours ago        up to hours                                  angry_spence
[email protected] ~]$ Docker exec-it  2a7a85124400  /bin/bash[email protected]:/# mysql-h 127.0.0.1-u root-p En ter Password:welcome to the MySQL Monitor.  
7. Commonly used docker instructions and parameters 1>. Docker Mirroring Instructions

Image retrieval
The Docker image is placed on the Docker hub of the https://registry.hub.docker.com, which is the address. You can search for images on the site, or use the command "Docker search image name" (e.g. Docker search Redis) to retrieve it.

Image download
Docker Pull Mirror Name

View the local mirror list
Docker images

Remove Mirror
Docker RMI Image-id

Remove all mirrors
Docker RMI $ (Docker images-q)

2>. Docker container directives

Run image as container
Docker Run--name container-name-d image-name
Where the--name party committee container name,-d means detached, meaning that after executing this command console will not be blocked, you can continue to enter the command operation. Such as:
Docker Run--name test-redis-d Redis

View a list of containers in operation
Docker PS
Use the following commands to view the containers for the running and stopping states:
Docker Ps-a

Stop container
Stop a container by container name or container ID
Docker Stop Container-name/container-id
Such as:
Docker Stop Test-redis

Start container
To start a container by container name or container ID
Docker start Container-name/container-id
Such as:
Docker start Test-redis

Set up the container to boot
Use the--restart parameter to set when using the Docker run.
No-container: Do not restart
On-failure-container: Exit status non-0 o'clock restart
Always: Restart all the Times
Such as:
Docker run--restart=always--name mysql5.7-p 3306:3306-e mysql_root_password=123456-d mysql:5.7

Port mappings
The ports that are used by the software running in the Docker container need to be mapped to the port on the current host for access. Docker port mappings are implemented with a-p parameter. For example, we mapped the 6379 port of the Redis container to the 6378 port on this machine:
Docker run-d-P 6378:6379--name Port-redis Redis

Delete Container
Docker RM Container-id

Remove all containers
Docker RM $ (Docker ps-a-Q)

View current Container Log
Docker logs Container-name/container-id
Such as:
Docker logs Port-redis

Landing container
A running container is actually a fully functional Linux operating system, so we can log in and access the container like a regular system.
We can use the following command, log in to access the current container, after logging on we can do the regular Linux system Operation command in the container, you can also use the Exit command to exit the login:
Docker exec-it Container-id/container-name Bash

8. How to resolve a situation where LAN access is not available

Mysql> Grant all privileges on * * to [email protected] '% ' identified by ' password ' with GRANT option;
Query OK, 0 rows affected, 1 warning (0.04 sec)


mysql> flush Privileges;
Query OK, 0 rows Affected (0.00 sec)

After the execution, and then through the tool to connect, you can connect.

Docker learn to install MySQL

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.