前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Docker 安装教程(Linux)

Docker 安装教程(Linux)

原创
作者头像
甄士隐
发布2022-03-08 17:52:54
5.2K0
发布2022-03-08 17:52:54
举报
文章被收录于专栏:混合云混合云

在 Linux 上安装Docker是常见的安装场景,并且安装过程非常简单。

通常难点在于 Linux 不同发行版之间的轻微区别,比如 Ubuntu 和 CentOS 之间的差异。接下来的示例基于 Ubuntu 版本 Linux,同样适用于更低或者更高的版本。

理论上,下面的示例在 CentOS 的各种版本上也是可以执行的。至于 Linux 操作系统是安装在自己的数据中心,还是第三方公有云,或是笔记本的虚拟机上,都没有任何的区别。

唯一需求就是这台机器是Linux 操作系统,并且能够访问https://get.docker.com

首先读者需要选择安装的 Docker 版本。当前有两个版本可供选择:社区版(Community Edition,CE)和企业版(Enterprise Edition,EE)。

Docker CE 是免费的,并且是接下来示例中将要使用的版本。

Docker EE 包含 Docker CE 中的全部功能,还包括了商业支持以及与其他 Docker 产品的集成,比如Docker 可信镜像库和通用控制面板。

下面的例子使用wget命令来运行一个 Shell 脚本,完成 Docker CE 的安装。

更多其他在 Linux 上安装 Docker 的方式,可以打开 Docker 主页面(www.docker.com),单击页面中 Get Started 按钮来获取。

注:在开始下面的步骤之前,要确认系统升级到最新的包,并且打了相应的安全补丁。

1.在 Linux 机器上打开一个新的 Shell。

2.使用wget从 https://get.docker.com 获取并运行 Docker 安装脚本,然后采用 Shell 中管道(pipe)的方式来执行这个脚本。先给出官方教程:

Install from a packageIf you cannot use Docker’s repository to install Docker, you can download the .rpm file foryour release and install it manually. You need to download a new file each time you want toupgrade Docker Engine 1. Go to https://download.docker.com/linux/centos/ and choose your version of CentOS.Then browse to x86_64/stable/Packages/ and download the .rpm file for theDocker version you want to install.Note To install a nightly or test (pre-release) package, change the word stable in theabove URL to nightly or test:https://docs.docker.com/engine/install/ 2. Install Docker Engine, changing the path below to the path where you downloaded theDocker package.$ sudo yum install /path/to/package.rpDocker is installed but not started. The docker group is created, but no users areadded to the group.Start Docker$ sudo systemctl start dockerVerify that Docker Engine is installed correctly by running the hello-world image$ sudo docker run hello-worlThis command downloads a test image and runs it in a container. When the containerruns, it prints a message and exits This installs and runs Docker Engine. Use sudo to run Docker commands. Continue to Post-installation steps for Linux to allow non-privileged users to run Docker commands and forother optional configuration steps

现在我就用我的服务器来演示一下:

代码语言:yaml
复制
# 安装yum安装器
sudo yum -y install yum-utils

sudo yum-config-manager \
--add-repo https://download.docker.com/linux/centos/docker-ce.repo

# 安装Docker
sudo yum install docker-ce docker-ce-cli containerd.io

# 启动docker并设置默认启动
systemctl start docker
systemctl enable docker

echo '{ "registry-mirrors":[ " https://docker.mirrors.ustc.edu.cn", "https://hub-mirror.c.163.com"] }' > /etc/docker/daemon.json
  1. 第二种
代码语言:yaml
复制
# 下载脚本文件
curl-fsSL https://get.docker.com -o get-docker.sh

# 运行安装脚本
sudo sh get-docker.sh

# 启动docker
# ubuntus
udoservice docker start

# CentOS
sudo systemctl start docker.service

# 设置开机自启动
systemctl enable docker

查看是否安装成功:

代码语言:yaml
复制
docker --version

以上就是我们的安装步骤.

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
容器镜像服务
容器镜像服务(Tencent Container Registry,TCR)为您提供安全独享、高性能的容器镜像托管分发服务。您可同时在全球多个地域创建独享实例,以实现容器镜像的就近拉取,降低拉取时间,节约带宽成本。TCR 提供细颗粒度的权限管理及访问控制,保障您的数据安全。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档