[1-docker-01]centos环境安装docker

官方参考文档

可以在官方docker桌面版本指导文档里找到适合自己的电脑平台进行参考,或者你是老司机的话直接自己上车。

如果不需要桌面版,也可以在官方docker engine版本指导文档里找到适合自己的平台进行参考,同样,老司机可以自己上车。

安装docker

我装了一台全新的centos,因为安装的mini版本,所以一些工具要自己安装下,由于虚拟机提供的终端并不好用,所以先在虚拟机里安装下net-tools,查看下ip,以便下一步ssh远程连接。

# 更新yum源
yum update -y

# 安装net-tools (ifconfig) 
yum install net-tools -y

然后使用ssh登陆:
[1-docker-01]centos环境安装docker_第1张图片
先来看一下系统架构:

# 查看系统架构
[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 - Community
 Version:           25.0.3
 API version:       1.44
 Go version:        go1.21.6
 Git commit:        4debf41
 Built:             Tue Feb  6 21:17:10 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          25.0.3
  API version:      1.44 (minimum version 1.24)
  Go version:       go1.21.6
  Git commit:       f417435
  Built:            Tue Feb  6 21:16:08 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        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: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/

你可能感兴趣的:(虚拟化,centos,docker)