安装docker,分离部署
·
单机文件系统:
ntfs – windows
xfs – linux
ext4 – linux
集群文件系统
vmfs
ocfs
安装docker
准备stream8虚拟机
1.配置主机名及ip
[root@localhost ~]# hostnamectl set-hostname docker
[root@localhost ~]# nmcli connection modify ens160 ipv4.method manual
ipv4.addresses 192.168.108.30/24 ipv4.gateway 192.168.108.2 ipv4.dns
192.168.108.2 autoconnect yes
[root@localhost ~]# nmcli con up ens160
2.卸载旧版本
[root@docter ~ 11:44:55]# yum remove docter-ce
No match for argument: docter-ce
No packages marked for removal.
Dependencies resolved.
Nothing to do.
Complete!
3.安装必要工具
[root@docter ~ 11:45:23]# yum install -y yum-utils device-mapper-persistent-data lvm2 vim
[root@docter ~ 11:46:55]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@docter ~ 11:47:31]# yum makecache
Docker CE Stable - x86_64 40 kB/s | 66 kB 00:01
CentOS Stream 8 - BaseOS 4.2 kB/s | 3.9 kB 00:00
CentOS Stream 8 - AppStream 533 B/s | 4.4 kB 00:08
Metadata cache created.
4.安装软件
[root@docker ~ 12:18:35]# yum install -y docker-ce
5.配置服务
[root@docker ~ 12:20:11]# systemctl enable docker.service --now
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
##查看docker版本
[root@docker ~ 12:21:55]# docker --version
Docker version 26.1.3, build b72abbb
##查看状态
[root@docker ~ 12:26:12]# systemctl status docker.service
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2026-05-08 12:21:55 CST; 4min 33s ago
Docs: https://docs.docker.com
Main PID: 11781 (dockerd)
Tasks: 10
Memory: 32.2M
CGroup: /system.slice/docker.service
└─11781 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
配置镜像加速器


[root@docker ~ 13:33:10]# vi /etc/docker/daemon.json
{
"registry-mirrors": [ "https://019e062e72da7ba3b57dd0af5f1b27.mirror.swr.myhuaweicloud.com" ]
}
##重新启动docker
[root@docker ~ 14:04:58]# systemctl restart docker
##确认配置
[root@docker ~ 14:05:15]# docker info
Client: Docker Engine - Community
Version: 26.1.3
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.14.0
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.27.0
Path: /usr/libexec/docker/cli-plugins/docker-compose
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 26.1.3
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Using metacopy: false
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 splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 8b3b7ca2e5ce38e8f31a34f35b2b68ceb8470d89
runc version: v1.1.12-0-g51d5e94
init version: de40ad0
Security Options:
seccomp
Profile: builtin
Kernel Version: 4.18.0-553.6.1.el8.x86_64
Operating System: CentOS Stream 8
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 3.549GiB
Name: docker
ID: d36b4833-5f04-4848-9ca3-d6130d8221c4
Docker Root Dir: /var/lib/docker
Debug Mode: false
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
https://019e062e72da7ba3b57dd0af5f1b27.mirror.swr.myhuaweicloud.com/ ##观察这边显示地址就行
Live Restore Enabled: false
运行第一个容器
[root@docker ~ 14:08:44]# docker run hello-world
Unable to find image 'hello-world:latest' locally ##观察
latest: Pulling from library/hello-world
4f55086f7dd0: Pull complete ##观察
Digest: sha256:f9078146db2e05e794366b1bfe584a14ea6317f027d10ef7dad65279026885
Status: Downloaded newer image for hello-world:latest
Hello from Docker! ###观察
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
其过程可以简单的描述为:
- 从本地查找hello-wrold镜像,没找到
- 从 Docker Hub 下载hello-world镜像。
- 启动hello-world容器
清空刚才的实验环境: 随后关机快照
#删除所有容器
[root@docker ~ 14:11:27]# docker rm -f $(docker ps -aq)
#删除镜像hello-world
[root@docker ~ 14:12:44]# docker rmi -f hello-world
Docker 五大核心组件及作用
Docker Client 客户端:命令行交互入口,发指令给服务端。
Docker Daemon 服务器:后台服务,接收指令、管理容器 / 镜像。
Docker Image 镜像:容器只读模板,包含运行环境和应用。
Docker Container 容器:镜像运行实例,独立隔离的应用运行环境。
Docker Registry 仓库:存放、共享镜像的仓库(如 Docker Hub)
docker C/S分离部署
配置俩台虚拟机
docker_server 192.168.108.30 and docker_client 192.168.108.31
分别配置主机名和ip
1.server配置
[root@docker_server ~]# yum install -y yum-utils device-mapper-persistent-data
lvm2 vim
[root@localhost ~]# yum-config-manager --add-repo
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/dockerce.repo
[root@docker_server ~]# yum makecache
[root@docker_server ~]# yum install -y docker-ce
[root@docker_server ~]# systemctl enable docker.service --now
[root@docker_server ~]# vi /etc/docker/daemon.json
{
"registry-mirrors": [
"https://054b8ac70e8010d90f2ac00ef29e6580.mirror.swr.myhuaweicloud.com" ]
}
# 按“Esc”,输入:wq保存并退出。
#重启容器引擎
[root@docker_server ~]# systemctl restart docker
配置服务
[root@docker_server ~]# vim /usr/lib/systemd/system/docker.service
# 在ExecStart参数中最后添加 -H tcp://0.0.0.0:2375,docker默认监听2375
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
-H tcp://0.0.0.0:2375
[root@docker_server ~]# systemctl daemon-reload
[root@docker_server ~]# systemctl restart docker.service
[root@docker_server ~]# systemctl stop firewalld
2.client配置
[root@docker-client ~]# yum install -y yum-utils device-mapper-persistent-data
lvm2 vim
[root@docker-client ~]# yum-config-manager --add-repo
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/dockerce.repo
[root@docker-client ~]# yum makecache
[root@docker-client ~]# yum install -y docker-ce-cli
验证
# client端连接server端执行命令
[root@docker-client ~]# docker -H 192.168.108.30 run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
查看内核
[root@docker ~ 16:23:18]# docker pull centos:7
7: Pulling from library/centos
2d473b07cdd5: Pull complete
Digest: sha256:be65f488b7764ad3638f236b7b515b3678369a5124c47b8d32916d6487418ea4
Status: Downloaded newer image for centos:7
docker.io/library/centos:7
[root@docker ~ 16:24:00]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 7 eeb6ee3f44bd 4 years ago 204MB
[root@docker ~ 16:24:11]# uname -r
4.18.0-553.6.1.el8.x86_64
[root@docker ~ 16:24:34]# docker run -it centos:7
[root@5c0b369a00ee /]# uname -r
4.18.0-553.6.1.el8.x86_64
[root@5c0b369a00ee /]# exit
exit
##公用一个宿主机内核
更多推荐

所有评论(0)