大数据物流项目:Docker 入门使用(二.五)
## 10–[掌握]-Docker 配置阿里云镜像加速
> 鉴于国内网络问题,后续拉取 Docker 镜像十分缓慢,配置加速器来解决,配置阿里云加速器。
- 1)、登录阿里云地址(需要注册)
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-mLaguI8W-1651888604583)(/img/1615539708242.png)]
- 2)、获取加速器地址:
```
https://yeu2889p.mirror.aliyuncs.com
```
- 3)、配置加速器地址配置,执行如下命令即可
```ini
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://yeu2889p.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
```
> Docker 引擎服务启动、停止和关闭命令:
![1615539901884](https://img-blog.csdnimg.cn/img_convert/aaac9696aaf49c255bad2e4d7de14488.png)
## 11–[掌握]-Docker 容器快速运行ContOS 系统
> 使用Docker创建容器Contanier,运行CentOS 7操作系统。
- 1)、拉取镜像(注册中心仓库)
```ini
[root@node1 ~]# docker pull centos:7
7: Pulling from library/centos
2d473b07cdd5: Pull complete
Digest: sha256:0f4ec88e21daf75124b8a9e5ca03c37a5e937e0e108a255d890492430789b60e
Status: Downloaded newer image for centos:7
docker.io/library/centos:7
[root@node1 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 7 8652b9f0cb4c 3 months ago 204MB
```
- 2)、创建容器
```ini
[root@node1 ~]# docker run -di --name=mycentos centos:7
21cc295413f0730ecdc64605081bab53775f982c56163713c8d0360e6a5f015d
[root@node1 ~]#
[root@node1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
21cc295413f0 centos:7 "/bin/bash" 11 seconds ago Up 10 seconds mycentos
```
- 3)、进入容器
```ini
[root@node1 ~]# docker exec -it mycentos /bin/bash
[root@21cc295413f0 /]#
[root@21cc295413f0 /]# hostname
21cc295413f0
[root@21cc295413f0 /]#
[root@21cc295413f0 /]# vi aa.txt
[root@21cc295413f0 /]#
[root@21cc295413f0 /]# more a
aa.txt anaconda-post.log
[root@21cc295413f0 /]# more aa.txt
Hello Docker!
```
## 12-[掌握]-Docker 帮助命令
> 已经安装部署Docker引擎:`systemctl start docker`
```ini
[root@node1 ~]# ps -ef|grep docker
root 1851 1 0 08:56 ? 00:00:01 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
```
> Docker 容器引擎,提供客户端:`docker`
![1615600508387](https://img-blog.csdnimg.cn/img_convert/44d7a70448197fe6f2479e60131360f0.png)
```ini
[root@node1 ~]# docker version
Client: Docker Engine - Community
Version: 20.10.5
API version: 1.41
Go version: go1.13.15
Git commit: 55c4c88
Built: Tue Mar 2 20:33:55 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.5
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: 363e9a8
Built: Tue Mar 2 20:32:17 2021
OS/Arch: linux/amd64
[root@node1 ~]# docker info
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
Server:
Containers: 1
Running: 0
Paused: 0
Stopped: 1
Images: 1
Server Version: 20.10.5
Storage Driver: overlay2
Backing Filesystem: xfs
[root@node1 ~]# docker --help
Usage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Options:
--config string Location of client config files (default "/root/.docker")
-c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default
context set with "docker context use")
-D, --debug Enable debug mode
-H, --host list Daemon socket(s) to connect to
-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/root/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
Management Commands:
app* Docker App (Docker Inc., v0.9.1-beta3)
builder Manage builds
buildx* Build with BuildKit (Docker Inc., v0.5.1-docker)
config Manage Docker configs
container Manage containers
context Manage contexts
image Manage images
manifest Manage Docker image manifests and manifest lists
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes
Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes
Run 'docker COMMAND --help' for more information on a command.
To get more help with docker, check out our guides at https://docs.docker.com/go/guides/
```
> 在Docker容器引擎中,最重要命令就是:`镜像命令和容器命令`。
![1615600776170](https://img-blog.csdnimg.cn/img_convert/bece53f8e8e2298020b6e795ac9a59a1.png)
## 13-[掌握]-Docker 镜像命令
> 首先,看一下镜像相关常用命令:搜索镜像`search`、拉取镜像`pull`、查看镜像`list`及删除镜像`rmi`
>
> [从注册中心仓库中获取镜像,对镜像进行管理操作]()
>
> 注册中心,仓库地址:https://hub.docker.com
![1615600863236](https://img-blog.csdnimg.cn/img_convert/815fa96f785e50fcae5098f81c067de8.png)
```ini
# 搜索镜像image
[root@node1 ~]# clear
[root@node1 ~]# docker search elasticsearch
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
elasticsearch Elasticsearch is a powerful open source sear… 4894 [OK]
nshou/elasticsearch-kibana Elasticsearch-7.10.1 Kibana-7.10.1 125 [OK]
itzg/elasticsearch Provides an easily configurable Elasticsearc… 71 [OK]
elastichq/elasticsearch-hq Official Docker image for ElasticHQ: Elastic… 70 [OK]
```
> 搜索镜像时,更多在WEB 界面搜索
![1615601089585](https://img-blog.csdnimg.cn/img_convert/365a7e032702df534bb9cdb6c3872792.png)
> 当搜索到镜像以后,可以仓库中将镜像拉取pull到本地镜像
>
> [每个镜像image,都有版本tag,所以在拉取镜像时,需要选择合适的版本tag](),当拉取镜像时,不指定tag版本,默认情况下将会拉取最新tag版本镜像。
```ini
[root@node1 ~]# docker pull elasticsearch:7.11.1
7.11.1: Pulling from library/elasticsearch
7a0437f04f83: Downloading [===> ] 5.934MB/75.18MB
744c7f8ba15d: Downloading [======================> ] 10.09MB/22.29MB
a2e5f03a9eab: Download complete
edcdb0cfb01b: Downloading [> ] 539.6kB/324.5MB
```
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-S1117LaN-1651888604585)(/img/1615601240320-1621314383189.png)]
> 当镜像拉取到本地以后,需要查看镜像和删除镜像
>
> - 1)、查看镜像
![1615601300360](https://img-blog.csdnimg.cn/img_convert/971214395ff081e7ec92625aa4cd500d.png)
> - 2)、删除镜像
![1615601348789](https://img-blog.csdnimg.cn/img_convert/188a5f0b5f0368506e3fc4348c242799.png)
```ini
[root@node1 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 7 8652b9f0cb4c 3 months ago 204MB
[root@node1 ~]#
[root@node1 ~]# docker rmi 8652b9f0cb4c
[root@node1 ~]#
[root@node1 ~]#
[root@node1 ~]# docker rmi centos:7
[root@node1 ~]#
```
## 14-[掌握]-Docker 容器命令之查看与创建
> 实际开发中,创建容器运行应用之前,首先获取对应镜像,往往都是从注册中心仓库中拉取,当将镜像拉取到本地以后,就可以创建容器。
>
> - 1)、容器查看,[本地有多少容器,有的运行,有的时停止的]()
>
> `Docker 中容器Container运行以线程方式运行,所以使用ps查看`
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ClkR1pwO-1651888604586)(/img/1615601617510-1621314383189.png)]
```ini
[root@node1 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
21cc295413f0 centos:7 "/bin/bash" 17 hours ago Exited (137) 17 hours ago mycentos
[root@node1 ~]#
[root@node1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@node1 ~]#
[root@node1 ~]#
[root@node1 ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
21cc295413f0 centos:7 "/bin/bash" 17 hours ago Exited (137) 17 hours ago mycentos
[root@node1 ~]#
[root@node1 ~]# docker ps -f status=exited
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
21cc295413f0 centos:7 "/bin/bash" 17 hours ago Exited (137) 17 hours ago mycentos
```
> - 2)、容器创建,有2种方式,容器创建时需要指定使用镜像
>
> [image(模板) -> container(实例)]()
![1615601873246](https://img-blog.csdnimg.cn/img_convert/0730261caf7bd27123762ddc17577e38.png)
> - 方式一:启动交互式容器,`docker run -it --name=centos 镜像名称:标签 /bin/bash`
![1615601963095](https://img-blog.csdnimg.cn/img_convert/0106681f9f7f62dfc733caec5ee26617.png)
```ini
[root@node1 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
21cc295413f0 centos:7 "/bin/bash" 17 hours ago Exited (137) 17 hours ago mycentos
[root@node1 ~]#
[root@node1 ~]# docker run -it centos:7 /bin/bash
[root@46188ebaf87f /]# hostname
46188ebaf87f
[root@46188ebaf87f /]#
[root@46188ebaf87f /]# exit
exit
[root@node1 ~]#
[root@node1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@node1 ~]#
[root@node1 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
46188ebaf87f centos:7 "/bin/bash" 32 seconds ago Exited (0) 6 seconds ago competent_fermi
21cc295413f0 centos:7 "/bin/bash" 17 hours ago Exited (137) 17 hours ago mycentos
```
> 当创建交互式容器时,创建完成以后,直接运行容器,并且进入容器中,如果退出容器,自动将容器关闭。
> - 2)、方式二:守护式方式创建容器,`docker run -di --name=容器名称 镜像名称:标签`
> - 采用守护式方法创建容器以后,需要登录容器(相当于登录操作系统)
> - 命令:`docker exec -it 容器名称(或者容器id) /bin/bash`
```ini
[root@node1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@node1 ~]#
[root@node1 ~]# docker run -di --name=mycentos2 centos:7
1741ea301b3f7c60992cd7b29a29747f15c46c6be6a916bbad213e16018a3303
[root@node1 ~]#
[root@node1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1741ea301b3f centos:7 "/bin/bash" 6 seconds ago Up 6 seconds mycentos2
[root@node1 ~]#
[root@node1 ~]#
[root@node1 ~]# docker exec -it mycentos2 /bin/bash
[root@1741ea301b3f /]#
[root@1741ea301b3f /]# hostname
1741ea301b3f
[root@1741ea301b3f /]#
```
> 实际项目中,创建容器时采用守护方式创建,使用exec进入容器进行操作。
## 15-[掌握]-Docker 容器命令之启动与停止
> 当容器创建完成以后,有时需要停止容器运行、启动容器运行,相关命令如下:
![1615602427828](https://img-blog.csdnimg.cn/img_convert/dc99debafbd33eb03133a76663b2a183.png)
> 可以重启容器(先停止,再启动)
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-18MPfKlH-1651888604587)(/img/1615602461159-1621314383189.png)]
```ini
[root@node1 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1741ea301b3f centos:7 "/bin/bash" 4 minutes ago Up 4 minutes mycentos2
e56430030fff centos:7 "/bin/bash" 5 minutes ago Exited (0) 5 minutes ago centos7
46188ebaf87f centos:7 "/bin/bash" 8 minutes ago Exited (0) 7 minutes ago competent_fermi
21cc295413f0 centos:7 "/bin/bash" 17 hours ago Exited (137) 17 hours ago mycentos
[root@node1 ~]#
[root@node1 ~]# docker start mycentos
mycentos
[root@node1 ~]#
[root@node1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1741ea301b3f centos:7 "/bin/bash" 4 minutes ago Up 4 minutes mycentos2
21cc295413f0 centos:7 "/bin/bash" 17 hours ago Up 3 seconds mycentos
[root@node1 ~]#
[root@node1 ~]# docker stop mycentos2
mycentos2
[root@node1 ~]#
[root@node1 ~]# docker kill 21cc295413f0
21cc295413f0
[root@node1 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1741ea301b3f centos:7 "/bin/bash" 5 minutes ago Exited (137) 25 seconds ago mycentos2
e56430030fff centos:7 "/bin/bash" 7 minutes ago Exited (0) 6 minutes ago centos7
46188ebaf87f centos:7 "/bin/bash" 9 minutes ago Exited (0) 8 minutes ago competent_fermi
21cc295413f0 centos:7 "/bin/bash" 17 hours ago Exited (137) 6 seconds ago mycentos
```
## 16-[掌握]-Docker 容器命令之IP 地址
> 当使用Docker 容器引擎,创建容器以后,每个容器运行时,都有IP地址,属于Docker容器内部IP地址。
```ini
[root@node1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4148cf3b3dea centos:7 "/bin/bash" 3 minutes ago Up 3 minutes centos7
827ff98c2a29 centos:7 "/bin/bash" 4 minutes ago Up 4 minutes centos
[root@node1 ~]#
[root@node1 ~]# ifconfig
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
inet6 fe80::42:d4ff:fef5:9869 prefixlen 64 scopeid 0x20<link>
ether 02:42:d4:f5:98:69 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 13 bytes 1768 (1.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.88.10 netmask 255.255.255.0 broadcast 192.168.88.255
inet6 fe80::20c:29ff:fea0:85 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:a0:00:85 txqueuelen 1000 (Ethernet)
RX packets 485440 bytes 672923357 (641.7 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 129820 bytes 8330903 (7.9 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 48 bytes 4080 (3.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 48 bytes 4080 (3.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
veth94d4a57: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::3408:a4ff:fe46:7687 prefixlen 64 scopeid 0x20<link>
ether 36:08:a4:46:76:87 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 656 (656.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
vetha19c80a: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::cc15:1fff:fe6d:991d prefixlen 64 scopeid 0x20<link>
ether ce:15:1f:6d:99:1d txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 656 (656.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:f6:83:da txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
```
> 如何查看容器中IP地址呢?
```ini
[root@node1 ~]# docker inspect centos
[
{
"Id": "827ff98c2a294a03191f4002bbf582d4e3ce84b0f3211c22c56ed3c561eb6dc1",
"Created": "2021-03-13T03:02:42.354813578Z",
"Path": "/bin/bash",
"Args": [],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 53376,
"ExitCode": 0,
"Error": "",
"StartedAt": "2021-03-13T03:02:47.515567445Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:8652b9f0cb4c0599575e5a003f5906876e10c1ceb2ab9fe1786712dac14a50cf",
"ResolvConfPath": "/var/lib/docker/containers/827ff98c2a294a03191f4002bbf582d4e3ce84b0f3211c22c56ed3c561eb6dc1/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/827ff98c2a294a03191f4002bbf582d4e3ce84b0f3211c22c56ed3c561eb6dc1/hostname",
"HostsPath": "/var/lib/docker/containers/827ff98c2a294a03191f4002bbf582d4e3ce84b0f3211c22c56ed3c561eb6dc1/hosts",
"LogPath": "/var/lib/docker/containers/827ff98c2a294a03191f4002bbf582d4e3ce84b0f3211c22c56ed3c561eb6dc1/827ff98c2a294a03191f4002bbf582d4e3ce84b0f3211c22c56ed3c561eb6dc1-json.log",
"Name": "/centos",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"CgroupnsMode": "host",
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "private",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/daba5b9305c5e683eafbe5e087d1bebee34c98be005db15649d54ad4477b5fe7-init/diff:/var/lib/docker/overlay2/c907f57265207bf28d834e05f41753b198a5b3df2b84ddd064e053d741e3ad5f/diff",
"MergedDir": "/var/lib/docker/overlay2/daba5b9305c5e683eafbe5e087d1bebee34c98be005db15649d54ad4477b5fe7/merged",
"UpperDir": "/var/lib/docker/overlay2/daba5b9305c5e683eafbe5e087d1bebee34c98be005db15649d54ad4477b5fe7/diff",
"WorkDir": "/var/lib/docker/overlay2/daba5b9305c5e683eafbe5e087d1bebee34c98be005db15649d54ad4477b5fe7/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "827ff98c2a29",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": true,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/bash"
],
"Image": "centos:7",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"org.label-schema.build-date": "20201113",
"org.label-schema.license": "GPLv2",
"org.label-schema.name": "CentOS Base Image",
"org.label-schema.schema-version": "1.0",
"org.label-schema.vendor": "CentOS",
"org.opencontainers.image.created": "2020-11-13 00:00:00+00:00",
"org.opencontainers.image.licenses": "GPL-2.0-only",
"org.opencontainers.image.title": "CentOS Base Image",
"org.opencontainers.image.vendor": "CentOS"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "958164ab6fd78db5b500d75ec0c798318a7d1a89cc4e1de3e168e3a062e7f8d9",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/958164ab6fd7",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "1da3cb4de7247d1002b27ced094ea5d7a6a2a2c23d8157b77461cbee886e8f1c",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "051cdc01a196f22b35b248f863b7212fa2256adb4f1decf877a09bd05bdd4d59",
"EndpointID": "1da3cb4de7247d1002b27ced094ea5d7a6a2a2c23d8157b77461cbee886e8f1c",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
}
}
]
```
> 删除容器:当容器不再被使用时,可以直接删除容器Contanier
![1615605219378](https://img-blog.csdnimg.cn/img_convert/aa108c489b4f9db4d4b033a0d20a4c3b.png)
> 当创建容器以后,并且运行时,包含IP地址,提供相关网络适配器将宿主机IP地址转换为容器IP地址。[此外,如果容器中运行服务,需要暴露端口号,需要设置容器端口号与宿主机端口号映射。]()
![image-20210518175026918](https://img-blog.csdnimg.cn/img_convert/06dd81d00cf1c749450d61ade1f733e7.png)
## 17-[理解]-Docker 应用部署之MySQL
> 接下来,采用Docker容器部署数据库和服务:MySQL数据库。
>
> 步骤:[①搜索镜像、②拉取镜像、③查看镜像、④启动容器、⑤停止容器、⑥移除容器]()
```ini
[root@node1 ~]# docker search mysql
[root@node1 ~]# docker pull centos/mysql-57-centos7
Using default tag: latest
latest: Pulling from centos/mysql-57-centos7
d8d02d457314: Pull complete
a11069b6e245: Pull complete
596303fb1aa3: Pull complete
a29499e779a7: Pull complete
17d1a52c2e00: Pull complete
ed24591227fe: Pull complete
de0ad46e3ed9: Pull complete
c62e4a984a9c: Pull complete
01d54c6bda68: Pull complete
Digest: sha256:e08ee4d43b7356607685b69bde6335e27cf20c020f345b6c6c59400183882764
Status: Downloaded newer image for centos/mysql-57-centos7:latest
docker.io/centos/mysql-57-centos7:latest
[root@node1 ~]# docker images
centos/mysql-57-centos7 latest f83a2938370c 17 months ago 452MB
```
> 命令:`docker run -dt --name=mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 centos/mysql-57-centos7`
>
> 其中在创建容器时,需要指定端口号映射
![1615605653675](https://img-blog.csdnimg.cn/img_convert/64e8826a420af065f8e89b1cedda9015.png)
> 指定端口号映射方式:
![1615605683345](https://img-blog.csdnimg.cn/img_convert/784f07f0f9b9e7d8ae7e1bfe2ba0d064.png)
```ini
[root@node1 ~]# docker run -di --name=mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 centos/mysql-57-centos7
b3da50687358586f0b0a430ba138b0a080b39dbf244de4f92152919f51a3dae9
[root@node1 ~]#
[root@node1 ~]#
[root@node1 ~]#
[root@node1 ~]#
[root@node1 ~]#
[root@node1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b3da50687358 centos/mysql-57-centos7 "container-entrypoin…" 40 seconds ago Up 6 seconds 0.0.0.0:3306->3306/tcp mysql
[root@node1 ~]# docker exec -it mysql /bin/bash
bash-4.2$ ps
PID TTY TIME CMD
202 pts/0 00:00:02 bash
211 pts/0 00:00:00 ps
bash-4.2$
bash-4.2$ ps -ef|grep mysql
mysql 1 0 2 03:22 ? 00:00:02 /opt/rh/rh-mysql57/root/usr/libexec/mysqld --defaults-file=/etc/my.cnf
mysql 202 0 12 03:23 pts/0 00:00:02 /bin/bash
mysql 212 202 0 03:23 pts/0 00:00:00 ps -ef
mysql 213 202 0 03:23 pts/0 00:00:00 grep mysql
```
![1615605915549](https://img-blog.csdnimg.cn/img_convert/4bca3e6e75d01f65d82476e980310892.png)
- 点赞
- 收藏
- 关注作者
评论(0)