docker 啓動一個mysql服務

目錄mysql

 

1、pull官方鏡像sql

2、查看鏡像docker

3、運行容器(開啓mysql服務)tcp

4、如何登錄到客戶端spa


1、pull官方鏡像

選擇一個指定的版本,或者直接拉去最新的mysql版本。code

docker pull mysql

2、查看鏡像

docker images進程

~]# docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
mysql                       latest              4f1413420360        25 hours ago        545MB

3、運行容器(開啓mysql服務)

最後冒號後面的是tag,就是版本,若是安裝有多個版本的mysql是否是啓動起來很方便。input

docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d mysql:8.0.22

docker ps查看啓動的mysql進程it

~]# docker ps
CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS              PORTS                               NAMES
b8319bd56ae3        mysql                          "docker-entrypoint.s…"   9 minutes ago       Up 9 minutes        3306/tcp, 33060/tcp                 keen_swanson
6a6cbd7a4dea        mysql                          "docker-entrypoint.s…"   9 minutes ago       Up 9 minutes        0.0.0.0:3306->3306/tcp, 33060/tcp   mysql

4、如何登錄到客戶端

 –link 鏈接運行的容器 mysql.5.7.21 爲以前首次運行時建立的容器名,冒號後爲鏡像名io

~]# docker run -it --link mysql:mysql --rm mysql sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -p'
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.22 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.22    |
+-----------+
1 row in set (0.00 sec)

mysql>
相關文章
相關標籤/搜索