在服务器上搭建docker环境
如果操作系统是centOS,可以使用yum安装
1.更新操作系统与内核
yum update -y
2.添加docker-ce yum 源
(在阿里云镜像站查找yum源)
清除rpm包及header
yum clear all & yum makecache
3.添加阿里云镜像加速器
.在阿里云上搜索 阿里云网页–>容器与中间件–>容器镜像服务ACR–>管理控制台–>镜像加速器 -->选择centOS 会显示配置镜像加速器的配置命令
(通过修改daemon配置文件/etc/docker/daemon.json来使用加速器)
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://ddrac55y.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
如果使用Ubuntu,就不能使用yum安装,使用apt-get install装或者snap安装
1.设置存储库
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl (software-properties-common #提示未找到命令)
使用这一条命令
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
PPA命令时会提示“sudo: add-apt-repository:找不到命令(command not found)”,这是因为没有安装PPA所致,把它安装上就可以了,只需要在终端中运行三条命令。
sudo apt-get install python-software-properties
sudo apt-get install software-properties-common
sudo apt-get update
2.添加docker的官方GPG密钥:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
3.设置稳定的存储库 amd64
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
4.安装docker引擎
sudo apt-get update
sudo apt-get install -y docker-ce #列出回购中可用的版本
5.在阿里云上搜索 阿里云网页–>容器与中间件–>容器镜像服务ACR–>管理控制台–>镜像加速器 -->选择ubuntu 会显示配置镜像加速器的配置命令
(通过修改daemon配置文件/etc/docker/daemon.json来使用加速器)
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://ddrac55y.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
6.运行hello-world图像
sudo docker run hello-world
此命令下载测试映像并在容器中运行。当容器运行时,它会打印一条消息并退出