webrx@us:~$ sudo apt update
[sudo] webrx 的密码:
命中:1 http://mirrors.aliyun.com/ubuntu focal InRelease
命中:2 http://mirrors.aliyun.com/ubuntu focal-updates InRelease
命中:3 http://mirrors.aliyun.com/ubuntu focal-backports InRelease
命中:4 http://mirrors.aliyun.com/ubuntu focal-security InRelease
命中:5 http://apt.postgresql.org/pub/repos/apt focal-pgdg InRelease
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
所有软件包均为最新。
webrx@us:~$ sudo apt list --upgradeable
正在列表... 完成
webrx@us:~$ sudo apt upgrade -y
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
正在计算更新... 完成
下列软件包是自动安装的并且现在不需要了:
linux-headers-5.4.0-96 linux-headers-5.4.0-96-generic linux-image-5.4.0-96-generic
linux-modules-5.4.0-96-generic linux-modules-extra-5.4.0-96-generic
使用'sudo apt autoremove'来卸载它(它们)。
升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
webrx@us:~$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.4 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.4 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
webrx@us:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.4 LTS
Release: 20.04
Codename: focal
webrx@us:~$
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
webrx@us:~$ curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
# Executing docker install script, commit: 93d2499759296ac1f9c510605fef85052a2c32be
+ sudo -E sh -c 'apt-get update -qq >/dev/null'
+ sudo -E sh -c 'DEBIAN_FRONTEND=noninteractive apt-get install -y -qq apt-transport-https ca-certificates curl >/dev/null'
+ sudo -E sh -c 'curl -fsSL "https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg" | gpg --dearmor --yes -o /usr/share/keyrings/docker-archive-keyring.gpg'
+ sudo -E sh -c 'echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu focal stable" > /etc/apt/sources.list.d/docker.list'
+ sudo -E sh -c 'apt-get update -qq >/dev/null'
+ sudo -E sh -c 'DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends docker-ce-cli docker-scan-plugin docker-ce >/dev/null'
+ version_gte 20.10
+ '[' -z '' ']'
+ return 0
+ sudo -E sh -c 'DEBIAN_FRONTEND=noninteractive apt-get install -y -qq docker-ce-rootless-extras >/dev/null'
+ sudo -E sh -c 'docker version'
Client: Docker Engine - Community
Version: 20.10.12
API version: 1.41
Go version: go1.16.12
Git commit: e91ed57
Built: Mon Dec 13 11:45:33 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.12
API version: 1.41 (minimum version 1.12)
Go version: go1.16.12
Git commit: 459d0df
Built: Mon Dec 13 11:43:42 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.12
GitCommit: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc:
Version: 1.0.2
GitCommit: v1.0.2-0-g52b36a2
docker-init:
Version: 0.19.0
GitCommit: de40ad0
================================================================================
To run Docker as a non-privileged user, consider setting up the
Docker daemon in rootless mode for your user:
dockerd-rootless-setuptool.sh install
Visit https://docs.docker.com/go/rootless/ to learn about rootless mode.
To run the Docker daemon as a fully privileged service, but granting non-root
users access, refer to https://docs.docker.com/go/daemon-access/
WARNING: Access to the remote API on a privileged Docker daemon is equivalent
to root access on the host. Refer to the 'Docker daemon attack surface'
documentation for details: https://docs.docker.com/go/attack-surface/
================================================================================
webrx@us:~$
webrx@us:~$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2022-02-19 13:24:36 CST; 11min ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 51456 (dockerd)
Tasks: 8
Memory: 28.1M
CGroup: /system.slice/docker.service
└─51456 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
2月 19 13:24:32 us dockerd[51456]: time="2022-02-19T13:24:32.093608663+08:00" level=warning msg="Your kernel does not support CPU realtime scheduler"
2月 19 13:24:32 us dockerd[51456]: time="2022-02-19T13:24:32.093620361+08:00" level=warning msg="Your kernel does not support cgroup blkio weight"
2月 19 13:24:32 us dockerd[51456]: time="2022-02-19T13:24:32.093626284+08:00" level=warning msg="Your kernel does not support cgroup blkio weight_device"
2月 19 13:24:32 us dockerd[51456]: time="2022-02-19T13:24:32.093857078+08:00" level=info msg="Loading containers: start."
2月 19 13:24:36 us dockerd[51456]: time="2022-02-19T13:24:36.112478891+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. >
2月 19 13:24:36 us dockerd[51456]: time="2022-02-19T13:24:36.213898321+08:00" level=info msg="Loading containers: done."
2月 19 13:24:36 us dockerd[51456]: time="2022-02-19T13:24:36.262993132+08:00" level=info msg="Docker daemon" commit=459d0df graphdriver(s)=overlay2 version=20.10.12
2月 19 13:24:36 us dockerd[51456]: time="2022-02-19T13:24:36.263529179+08:00" level=info msg="Daemon has completed initialization"
2月 19 13:24:36 us systemd[1]: Started Docker Application Container Engine.
2月 19 13:24:36 us dockerd[51456]: time="2022-02-19T13:24:36.314628027+08:00" level=info msg="API listen on /run/docker.sock"
webrx@us:~$ sudo service --status-all
[ + ] apparmor
[ + ] apport
[ + ] atd
[ - ] console-setup.sh
[ + ] cron
[ - ] cryptdisks
[ - ] cryptdisks-early
[ + ] dbus
[ + ] docker
[ - ] grub-common
[ - ] hwclock.sh
[ + ] irqbalance
[ - ] iscsid
[ - ] keyboard-setup.sh
[ + ] kmod
[ - ] lvm2
[ - ] lvm2-lvmpolld
[ + ] multipath-tools
[ - ] open-iscsi
[ + ] open-vm-tools
[ - ] plymouth
[ - ] plymouth-log
[ + ] postgresql
[ + ] procps
[ - ] rsync
[ + ] rsyslog
[ - ] screen-cleanup
[ + ] ssh
[ + ] sysstat
[ + ] udev
[ + ] ufw
[ + ] unattended-upgrades
[ + ] uuidd
webrx@us:~$ sudo service docker status
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2022-02-19 13:24:36 CST; 12min ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 51456 (dockerd)
Tasks: 8
Memory: 28.1M
CGroup: /system.slice/docker.service
└─51456 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
2月 19 13:24:32 us dockerd[51456]: time="2022-02-19T13:24:32.093608663+08:00" level=warning msg="Your kernel does not support CPU realtime scheduler"
2月 19 13:24:32 us dockerd[51456]: time="2022-02-19T13:24:32.093620361+08:00" level=warning msg="Your kernel does not support cgroup blkio weight"
2月 19 13:24:32 us dockerd[51456]: time="2022-02-19T13:24:32.093626284+08:00" level=warning msg="Your kernel does not support cgroup blkio weight_device"
2月 19 13:24:32 us dockerd[51456]: time="2022-02-19T13:24:32.093857078+08:00" level=info msg="Loading containers: start."
2月 19 13:24:36 us dockerd[51456]: time="2022-02-19T13:24:36.112478891+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. >
2月 19 13:24:36 us dockerd[51456]: time="2022-02-19T13:24:36.213898321+08:00" level=info msg="Loading containers: done."
2月 19 13:24:36 us dockerd[51456]: time="2022-02-19T13:24:36.262993132+08:00" level=info msg="Docker daemon" commit=459d0df graphdriver(s)=overlay2 version=20.10.12
2月 19 13:24:36 us dockerd[51456]: time="2022-02-19T13:24:36.263529179+08:00" level=info msg="Daemon has completed initialization"
2月 19 13:24:36 us systemd[1]: Started Docker Application Container Engine.
2月 19 13:24:36 us dockerd[51456]: time="2022-02-19T13:24:36.314628027+08:00" level=info msg="API listen on /run/docker.sock"
webrx@us:~$
webrx@us:~$ sudo adduser $USER docker
[sudo] webrx 的密码:
正在添加用户"webrx"到"docker"组...
正在将用户“webrx”加入到“docker”组中
完成。
webrx@us:~$ sudo adduser webrx docker
用户"webrx"已经属于"docker"组。
webrx@us:~$ docker version
Client: Docker Engine - Community
Version: 20.10.12
API version: 1.41
Go version: go1.16.12
Git commit: e91ed57
Built: Mon Dec 13 11:45:33 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/version": dial unix /var/run/docker.sock: connect: permission denied
webrx@us:~$ docker --version
Docker version 20.10.12, build e91ed57
国内从 DockerHub 拉取镜像有时会遇到困难,此时可以配置镜像加速器。Docker 官方和国内很多云服务商都提供了国内加速器服务,例如:
科大镜像:https://docker.mirrors.ustc.edu.cn/
网易:https://hub-mirror.c.163.com/
阿里云:https://<你的ID>.mirror.aliyuncs.com
七牛云加速器:https://reg-mirror.qiniu.com
Docker中国区官方镜像https://registry.docker-cn.com
网易http://hub-mirror.c.163.com
ustc 中国科技大学https://docker.mirrors.ustc.edu.cn
#创建或修改 /etc/docker/daemon.json 文件,修改为如下形式
webrx@us:~$ sudo vim /etc/docker/daemon.json 内容如下 按esc 输入:wq保存文件
{
"registry-mirrors": [
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn"
]
}
webrx@us:~$ docker info
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Docker Buildx (Docker Inc., v0.7.1-docker)
scan: Docker Scan (Docker Inc., v0.12.0)
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 20.10.12
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc version: v1.0.2-0-g52b36a2
init version: de40ad0
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 5.4.0-99-generic
Operating System: Ubuntu 20.04.4 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.81GiB
Name: us
ID: M744:MAFZ:O5ZB:RZZ6:X5SU:RWUN:MWLL:CNUR:ZPU3:XSDR:UWBD:GQOF
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
https://registry.docker-cn.com/
http://hub-mirror.c.163.com/
https://docker.mirrors.ustc.edu.cn/
Live Restore Enabled: false
WARNING: No swap limit support
查看加速是否生效
webrx@us:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
webrx@us:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 17b062d639f4 29 hours ago 519MB
webrx@us:~$ docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
6552179c3509: Pull complete
d69aa66e4482: Pull complete
3b19465b002b: Pull complete
7b0d0cfe99a1: Pull complete
9ccd5a5c8987: Pull complete
2dab00d7d232: Pull complete
5d726bac08ea: Pull complete
11bb049c7b94: Pull complete
7fcdd679c458: Pull complete
11585aaf4aad: Pull complete
5b5dc265cb1d: Pull complete
fd400d64ffec: Pull complete
Digest: sha256:e3358f55ea2b0cd432685d7e3c79a33a85c7a359b35fa87fc4993514b9573446
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest
查看镜像文件的相关信息
webrx@us:~$ docker inspect mysql
[
{
"Id": "sha256:17b062d639f4a10bf2439de7204856ea552a68fa5d7cd2f28c16066e340358c1",
"RepoTags": [
"mysql:latest"
],
"RepoDigests": [
"mysql@sha256:e3358f55ea2b0cd432685d7e3c79a33a85c7a359b35fa87fc4993514b9573446"
],
"Parent": "",
"Comment": "",
"Created": "2022-02-18T01:23:30.594541792Z",
"Container": "f27f850d7ce7da5c1407f71bf26deba6a66d30b95fa6796dd9f39eda199e553b",
"ContainerConfig": {
"Hostname": "f27f850d7ce7",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"3306/tcp": {},
"33060/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"GOSU_VERSION=1.14",
"MYSQL_MAJOR=8.0",
"MYSQL_VERSION=8.0.28-1debian10"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD [\"mysqld\"]"
],
"Image": "sha256:a19801229fca3ba3ecf3f792da774f8e30653018e673cf79fc8d97b3a0beeff1",
"Volumes": {
"/var/lib/mysql": {}
},
"WorkingDir": "",
"Entrypoint": [
"docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": {}
},
"DockerVersion": "20.10.7",
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"3306/tcp": {},
"33060/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"GOSU_VERSION=1.14",
"MYSQL_MAJOR=8.0",
"MYSQL_VERSION=8.0.28-1debian10"
],
"Cmd": [
"mysqld"
],
"Image": "sha256:a19801229fca3ba3ecf3f792da774f8e30653018e673cf79fc8d97b3a0beeff1",
"Volumes": {
"/var/lib/mysql": {}
},
"WorkingDir": "",
"Entrypoint": [
"docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": null
},
"Architecture": "amd64",
"Os": "linux",
"Size": 519356694,
"VirtualSize": 519356694,
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/59511d90c6a21404d0c3176e47de05d56e118d3f2dfcc926574d9bdadb20ffe1/diff:/var/lib/docker/overlay2/596ba5cd557a63f0a9e1856b2ef2975880ae9cd0bd1fb42af65221e9d0ec3372/diff:/var/lib/docker/overlay2/3142de1b074378b2ff042e1a1386fef09e0154115b0352beba8334ab7df6440c/diff:/var/lib/docker/overlay2/7977c30651bce447efec27f203cd5f05b629720713e512dfba9be1da43576317/diff:/var/lib/docker/overlay2/f4e747f7cc4117ca424b57cc67509ef82d7b70f5708dc1f802ca794216065259/diff:/var/lib/docker/overlay2/8b8f8f2f73675d870a2e54fb9ec9f3d7893158d7b2cc8b74398ba337fcbab36e/diff:/var/lib/docker/overlay2/717f0fc6b155b1fddb15e56bc78fee04d2676d1c6e9fd1e6ef3ec72b965fdef9/diff:/var/lib/docker/overlay2/dd92e17fa027a68687fcab03245416e92c417c093ae4962fccd8050846860974/diff:/var/lib/docker/overlay2/eac50df9a1bac9e8dc9dcbf9c69ec449042d3e1051b857f83c77f8abe6d7abcb/diff:/var/lib/docker/overlay2/9440a291c7b2982a08aacc741ee0f089e2d54319a44ce25af4ba8eb3db8cee17/diff:/var/lib/docker/overlay2/9f20860d5ba2968643cf5473875a426298fa345f4e4a4983fc6392052da58927/diff",
"MergedDir": "/var/lib/docker/overlay2/78ced0baf6f81213504f802008c350f0f8435a17c2a2a3899f52e65f4876ec8b/merged",
"UpperDir": "/var/lib/docker/overlay2/78ced0baf6f81213504f802008c350f0f8435a17c2a2a3899f52e65f4876ec8b/diff",
"WorkDir": "/var/lib/docker/overlay2/78ced0baf6f81213504f802008c350f0f8435a17c2a2a3899f52e65f4876ec8b/work"
},
"Name": "overlay2"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:f18b02b14138b6f9808f9843cc645e2edd64b02ca1c87e671355f56d1b4b5ec6",
"sha256:cec83252c1b64341aecd93049e5740a244bd121d272997ead7306c83eb88eee6",
"sha256:88bee9dc2401e913ce28646de90910227350c816bd10cc3d3ec6ef71b9dd68be",
"sha256:ced951e096b9f3bd8685220540ed157704c1f09a7224ecccc1a0748cdbb858e9",
"sha256:0147a12f509faefda39861075d14ed7604cac10fc32117868dc51792a6020dac",
"sha256:b2bde2ef1f635f1f2c63e3da55f1c967c29b4cd01e64d2aaf62fbdcb870baac7",
"sha256:a6aad77fe0357f701634d0939b3b728b23d02b735b554475952a9874b4f8c0f9",
"sha256:da90c9132777439e7f17dfded48f3fe9625e0237e7e13cf4dcaa1a9604562a2e",
"sha256:8c9559afb9b9645e595aa035727f805504c384ad67621cb7390cfce9b4a9e119",
"sha256:73754ed5eff30fc2edea24373d77d049184dd93d8563e6cde863f40dc60c5a26",
"sha256:3d0737b0f80c06c6e5d071c1c484c275b95b38a05865e0047d1d59874485e505",
"sha256:ab1580f17d51ae77719c561b22c2d269dd806d9f0b36cf1f20d43c877a1efd1e"
]
},
"Metadata": {
"LastTagTime": "0001-01-01T00:00:00Z"
}
}
]
webrx@us:~$
hub.docker.com官方查看使用帮助
webrx@us:~$ docker run -itd --name m8 -P -e MYSQL_ROOT_PASSWORD=root mysql
4d850a20782ea109c994fe301d569ea6ef5be2c4cb2b02672ea03b6f94af583c
webrx@us:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4d850a20782e mysql "docker-entrypoint.s…" 6 seconds ago Up 5 seconds 0.0.0.0:49154->3306/tcp, :::49154->3306/tcp, 0.0.0.0:49153->33060/tcp, :::49153->33060/tcp m8
webrx@us:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4d850a20782e mysql "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:49154->3306/tcp, :::49154->3306/tcp, 0.0.0.0:49153->33060/tcp, :::49153->33060/tcp m8
webrx@us:~$
测试容器 ubuntu 192.168.0.68
C:\>mysql -h192.168.0.68 -uroot -p -P49154
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.28 MySQL Community Server - GPL
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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 versioin();
ERROR 1046 (3D000): No database selected
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.28 |
+-----------+
1 row in set (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2022-02-19 07:09:42 |
+---------------------+
1 row in set (0.00 sec)
mysql> show variables like 'char%';
+--------------------------+--------------------------------+
| Variable_name | Value |
+--------------------------+--------------------------------+
| character_set_client | utf8mb3 |
| character_set_connection | utf8mb3 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb3 |
| character_set_server | utf8mb4 |
| character_set_system | utf8mb3 |
| character_sets_dir | /usr/share/mysql-8.0/charsets/ |
+--------------------------+--------------------------------+
8 rows in set (0.01 sec)
webrx@us:~$ docker run -itd --name m3308 -p 3308:3306 -e MYSQL_ROOT_PASSWORD=root -e TZ="Asia/Shanghai" mysql
56552fa965101f1b0dfc35b2c88de9a1c7eb6843a3bc586e7ab748d00d72ef7b
webrx@us:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
56552fa96510 mysql "docker-entrypoint.s…" 3 seconds ago Up 2 seconds 33060/tcp, 0.0.0.0:3308->3306/tcp, :::3308->3306/tcp m3308
4d850a20782e mysql "docker-entrypoint.s…" 8 minutes ago Up 8 minutes 0.0.0.0:49154->3306/tcp, :::49154->3306/tcp, 0.0.0.0:49153->33060/tcp, :::49153->33060/tcp m8
webrx@us:~$
C:\>mysql -h192.168.0.68 -uroot -p -P3308
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.28 MySQL Community Server - GPL
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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 now();
+---------------------+
| now() |
+---------------------+
| 2022-02-19 15:15:17 |
+---------------------+
1 row in set (0.00 sec)
1. docker run -itd --name m8 -P -e MYSQL_ROOT_PASSWORD=root mysql
2. docker run -itd --name m3308 -p 3308:3306 -e MYSQL_ROOT_PASSWORD=root -e TZ="Asia/Shanghai" mysql
-P 随机端口号 41954:3306
-p 3308:3306
-itd
--name m330
-e MYSQL_ROOT_PASSWORD=root
-e TZ="Asia/Shanghai" #时区
--restart=always #容器随docker自动启动
3. docker run -it --rm mysql mysql -h192.168.0.68 -uroot -P3308 -p
webrx@us:~$ docker run -it --rm mysql mysql -h192.168.0.68 -uroot -P3308 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.28 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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.28 |
+-----------+
1 row in set (0.00 sec)
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2022-02-19 15:22:36 |
+---------------------+
1 row in set (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> create databse db;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'databse db' at line 1
mysql> create database db;
Query OK, 1 row affected (0.01 sec)
mysql> use db;
Database changed
mysql> create table t(id int,name varchar(30));
Query OK, 0 rows affected (0.01 sec)
mysql> insert into t set id=10,name='lisi';
Query OK, 1 row affected (0.01 sec)
mysql> insert into t set id=20,name='wangwu';
Query OK, 1 row affected (0.01 sec)
mysql> select * from t;
+------+--------+
| id | name |
+------+--------+
| 10 | lisi |
| 20 | wangwu |
+------+--------+
2 rows in set (0.00 sec)
mysql> select * from t;
+------+--------+
| id | name |
+------+--------+
| 10 | lisi |
| 20 | wangwu |
| 55 | ?? |
+------+--------+
3 rows in set (0.00 sec)
mysql>
webrx@us:~$ docker ps -aq
56552fa96510
4d850a20782e
webrx@us:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
56552fa96510 mysql "docker-entrypoint.s…" 11 minutes ago Up 11 minutes 33060/tcp, 0.0.0.0:3308->3306/tcp, :::3308->3306/tcp m3308
4d850a20782e mysql "docker-entrypoint.s…" 19 minutes ago Up 19 minutes 0.0.0.0:49154->3306/tcp, :::49154->3306/tcp, 0.0.0.0:49153->33060/tcp, :::49153->33060/tcp m8
webrx@us:~$
webrx@us:~$ docker rm --help
Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...]
Remove one or more containers
Options:
-f, --force Force the removal of a running container (uses SIGKILL)
-l, --link Remove the specified link
-v, --volumes Remove anonymous volumes associated with the container
webrx@us:~$ docker rm $(docker ps -aq) -f #强制删除所有容器,包括正在运行的容器
56552fa96510
4d850a20782e
webrx@us:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
webrx@us:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES