Docker - 应用容器引擎安装教程

in 技术分享 / 0 评论 / 363阅读

Docker是一个应用容器引擎软件,可以使开发者将应用程序从一个计算机快速地移动到另一个计算机运行。容器与虚拟机的区别,容器是应用层的虚拟化,多个容器可以在同一台机器运行,与其他容器共享操作系统内核,容器占用空间更少;虚拟机是硬件的虚拟化,可以将一台服务器虚拟出多台服务器,每个虚拟机都包含独立的操作系统、核心、内存等,占用更大、启动速度较大。
Docker的出现解决运行环境不一致导致的各种文件,在容器内部署好运行环境及程序,将容器打包成镜像后,在其他机器直接运行即可,没有了环境冲突、缺少变量等问题。

Docker

Centos安装

卸载旧版本程序;安装所需软件包,yum-utils提供了yum-config-manager,并且device mapper依赖于device-mapper-persistent-data lvm2

yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
yum -y install yum-utils device-mapper-persistent-data lvm2

设置仓库地址

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# 阿里云源
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 清华大学源
yum-config-manager --add-repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo

安装Docker Engine-Community和containerd

yum -y install docker-ce docker-ce-cli containerd.io

Ubuntu安装

卸载旧版本程序

apt-get remove docker docker-engine docker.io containerd runc

安装apt依赖

apt-get update
apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

安装docker

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# 阿里云源
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# 清华大学源
curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/ $(lsb_release -cs) stable"

apt-get update
apt-get install docker-ce docker-ce-cli containerd.io

ubuntu 22.04安装

首先更新现有软件包列表和安装使用https相关软件包

apt update
apt install apt-transport-https ca-certificates curl software-properties-common

添加docker存储库GPG密钥到系统,添加Docker存储库到APT源

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# 清华源
curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

更行软件包列表,安装docker

apt update
apt-cache policy docker-ce
apt install docker-ce

debian11 安装

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo  "deb [arch="$(dpkg --print-architecture)" signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null

# 清华源
curl -fsSL  https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo  "deb [arch="$(dpkg --print-architecture)" signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian/ "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null

更行软件包列表,安装docker等组件

apt-get update
apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

docker-composer

Docker-Composer是一个定义和运行多容器Docker的工具。可以通过编写YML文件来配置应用程序所需的所有服务,再使用一个命令,即可从YML文件配置中创建并启动容器。
安装docker-composer

curl -SL https://github.com/docker/compose/releases/download/v2.4.1/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version
回复