Install Docker in Linux

Docker官网链接: https://docs.docker.com/

1.确定Linux版本

新版本的Docker对Linux系统版本有一定的要求。如果Linux的发行版系统是centOS,安装最新版的docker需要centOS 7以上的系统。

在Docker安装帮助页面查看支持的系统版本。

Docker帮助页面:https://docs.docker.com/engine/install/centos/

打开terminal,输入查看系统信息。

bash 复制代码
cat /etc/os-release

确保自己的系统满足安装要求。

rust 复制代码
[root@VM-8-7-centos server]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

2.安装Docker

官网提供的软件源速度比较慢,这里使用阿里云的软件源。

step 1: 安装必要的一些系统工具

bash 复制代码
sudo yum install -y yum-utils device-mapper-persistent-data lvm2

Step 2: 添加软件源信息

bash 复制代码
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

Step 3: 更新yum索引列表并安装Docker引擎

bash 复制代码
sudo yum makecache fast

yum索引列表没有更新可以直接使用yum makecache

bash 复制代码
sudo yum install docker-ce

安装过程中会提示确认,输入y以确认。

Step 4: 开启Docker服务

javascript 复制代码
sudo service docker start

3.测试是否安装成功

在Terminal中输入docker version,安装成功会提示以下信息。


javascript 复制代码
[root@VM-8-7-centos server]# docker version
Client: Docker Engine - Community
 Version:           24.0.7
 API version:       1.43
 Go version:        go1.20.10
 Git commit:        afdd53b
 Built:             Thu Oct 26 09:11:35 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.7
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.10
  Git commit:       311b9ff
  Built:            Thu Oct 26 09:10:36 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.24
  GitCommit:        61f9fd88f79f081d64d6fa3bb1a0dc71ec870523
 runc:
  Version:          1.1.9
  GitCommit:        v1.1.9-0-gccaecfc
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

4.配置下载docker镜像的仓库

docker的默认仓库Docker Hub下载速度在国内是很慢的,需要我们替换为阿里云的仓库。

打开腾讯云的官网,搜索容器,找到容器与镜像服务。

进入容器与镜像服务页面,点击镜像加速器。

依据页面的提示,在Terminal中输入以下指令:

4.1.执行以下命令,打开 /etc/docker/daemon.json 配置文件。

bash 复制代码
vim /etc/docker/daemon.json

4.2 按 i 切换至编辑模式,添加以下内容,并保存。

bash 复制代码
{
   "registry-mirrors": [
   "https://mirror.ccs.tencentyun.com"
  ]
}

4.3 执行以下命令,重启 Docker 即可。示例命令以 CentOS 7 为例。

bash 复制代码
sudo systemctl restart docker

5.测试HelloWorld镜像

在Terminal中输入docker run hello-world,如下表示 Docker成功安装~

javascript 复制代码
[root@VM-8-7-centos server]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
719385e32844: Pull complete
Digest: sha256:88ec0acaa3ec199d3b7eaf73588f4518c25f9d34f58ce9a0df68429c5af48e8d
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/
相关推荐
热爱嵌入式的小许1 小时前
Linux基础项目开发1:量产工具——显示系统
linux·运维·服务器·韦东山量产工具
雪域迷影4 小时前
PostgreSQL Docker Error – 5432: 地址已被占用
数据库·docker·postgresql
福大大架构师每日一题5 小时前
22.1 k8s不同role级别的服务发现
容器·kubernetes·服务发现
韩楚风5 小时前
【linux 多进程并发】linux进程状态与生命周期各阶段转换,进程状态查看分析,助力高性能优化
linux·服务器·性能优化·架构·gnu
莹雨潇潇5 小时前
Docker 快速入门(Ubuntu版)
java·前端·docker·容器
陈苏同学5 小时前
4. 将pycharm本地项目同步到(Linux)服务器上——深度学习·科研实践·从0到1
linux·服务器·ide·人工智能·python·深度学习·pycharm
Ambition_LAO5 小时前
解决:进入 WSL(Windows Subsystem for Linux)以及将 PyCharm 2024 连接到 WSL
linux·pycharm
Pythonliu75 小时前
茴香豆 + Qwen-7B-Chat-Int8
linux·运维·服务器
你疯了抱抱我5 小时前
【RockyLinux 9.4】安装 NVIDIA 驱动,改变分辨率,避坑版本。(CentOS 系列也能用)
linux·运维·centos
追风赶月、5 小时前
【Linux】进程地址空间(初步了解)
linux