官方参考文档
可以在官方docker桌面版本指导文档里找到适合自己的电脑平台进行参考,或者你是老司机的话直接自己上车。
如果不需要桌面版,也可以在官方docker engine版本指导文档里找到适合自己的平台进行参考,同样,老司机可以自己上车。
安装docker
我装了一台全新的centos,因为安装的mini版本,所以一些工具要自己安装下,由于虚拟机提供的终端并不好用,所以先在虚拟机里安装下net-tools,查看下ip,以便下一步ssh远程连接。
# 更新yum源
yum update -y# 安装net-tools (ifconfig)
yum install net-tools -y
然后使用ssh登陆:
先来看一下系统架构:
# 查看系统架构
[root@king ~]# uname -a
Linux king 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
安装一下日常工具和kvm相关依赖:
yum update -y && \
yum install -y vim less wget net-tools iputils-ping curl git && \
yum install -y libvirt libvirt-client virt-install qemu-kvm genisoimage qemu-guest-agent libguestfs-tools
以为是安装的centos mini,所以不存在旧版本docker,如果有的话需要先卸载:
yum erase docker \docker-client \docker-client-latest \docker-common \docker-latest \docker-latest-logrotate \docker-logrotate \docker-selinux \docker-engine-selinux \docker-engine \docker-ce`
运行以下命令,下载docker-ce的yum源:
sudo wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
运行以下命令,安装Docker:
sudo yum -y install docker-ce
启动 Docker 并设置开机自启:
systemctl start docker
systemctl enable docker
验证安装:
docker version
验证安装结果:
[root@king ~]# docker version
Client: Docker Engine - CommunityVersion: 25.0.3API version: 1.44Go version: go1.21.6Git commit: 4debf41Built: Tue Feb 6 21:17:10 2024OS/Arch: linux/amd64Context: defaultServer: Docker Engine - CommunityEngine:Version: 25.0.3API version: 1.44 (minimum version 1.24)Go version: go1.21.6Git commit: f417435Built: Tue Feb 6 21:16:08 2024OS/Arch: linux/amd64Experimental: falsecontainerd:Version: 1.6.28GitCommit: ae07eda36dd25f8a1b98dfbf587313b99c0190bbrunc:Version: 1.1.12GitCommit: v1.1.12-0-g51d5e94docker-init:Version: 0.19.0GitCommit: de40ad0
验证运行:
docker run hello-world
验证运行结果:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:4bd78111b6914a99dbc560e6a20eab57ff6655aea4a80c50b0c5491968cbc2e6
Status: Downloaded newer image for hello-world:latestHello 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 theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bashShare 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/