# docker pull mysql
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/mysql latest d9124e6c552f 12 days ago 383.4 MB
运行容器: 1:正常运行。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
启动容器:
# docker run --name cmh-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d docker.io/mysql
进入容器:
# docker-enter cmh-mysql
进入mysql:
root@3a2b8ab0d971:~# mysql -u root -pmy-secret-pw
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.16 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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>
查看容器:
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c38f50a540ff docker.io/mysql "docker-entrypoint.sh" 9 seconds ago Up 8 seconds 0.0.0.0:3306->3306/tcp cmh-mysql
查看端口:
# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp6 0 0 :::3306 :::* LISTEN 28657/docker-proxy
查看宿主机上的mysql数据:
# cd /opt/data/mysql
# ll
total 188452
-rw-r-----. 1 systemd-bus-proxy ssh_keys 56 Dec 6 16:01 auto.cnf
-rw-r-----. 1 systemd-bus-proxy ssh_keys 1325 Dec 6 16:01 ib_buffer_pool
-rw-r-----. 1 systemd-bus-proxy ssh_keys 79691776 Dec 6 17:16 ibdata1
-rw-r-----. 1 systemd-bus-proxy ssh_keys 50331648 Dec 6 17:16 ib_logfile0
-rw-r-----. 1 systemd-bus-proxy ssh_keys 50331648 Dec 6 16:01 ib_logfile1
-rw-r-----. 1 systemd-bus-proxy ssh_keys 12582912 Dec 6 17:16 ibtmp1
drwxr-x---. 2 systemd-bus-proxy ssh_keys 4096 Dec 6 16:01 mysql
drwxr-x---. 2 systemd-bus-proxy ssh_keys 8192 Dec 6 16:01 performance_schema
drwxr-x---. 2 systemd-bus-proxy ssh_keys 8192 Dec 6 16:01 sys