初识Docker
Docker官网
Docker官方帮助文档
一些推荐:Docker中文社区
1 安装Docker
Docker安装:官方帮助文档中的Get Docker,选择Docker Desktop for Linux,然后选择右边菜单栏的Docker Engine。
再选择右边菜单中的Install Docker Engine on Ubuntu,就可以看到详细介绍,我已经选好,点击链接即可直达。
- Prerequisites
我的是Ubuntu 20.04LTS,步骤如下:
卸载旧的:我这里不需要 - Install Docker
四种方法,需要使用其他方法可看文档,我直接选择的第二种方法:Set up Docker’s package repository.,点击链接即可直达。
- 步骤如下:
- Set up the repository
#Update the apt package index
sudo apt-get update
#install packages to allow apt to use a repository over HTTPS:
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
#Add Docker’s official GPG key:
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt
#Use the following command to set up the repository:\应该是连接两行用的
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
- Install Docker Engine
#Update the apt package index:
sudo apt-get update
#Receiving a GPG error, look into the url above(Docker’s package repository).
#Install Docker Engine, containerd, and Docker Compose.
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
#Verify that the Docker Engine installation is successful by running the hello-world image:
sudo docker run hello-world
一些知识补充:linux下的etc文件夹;curl 命令详解;GPG密钥的生成与使用;Linux命令之tee命令
-
最后一行的验证语句得到的结果:
-
如果要使用方法1,前面安装Docker Engine的步骤是通用的,只是多了下面安装Docker Desktop用的包和安装方法,不用DeskTop的可以略过,Desktop的安装步骤参考:Install on Ubuntu
Download latest DEB package.点击该链接就会下载:
Install the package with apt as follows:sudo apt-get update sudo apt-get install ./docker-desktop-<version>-<arch>.deb
2 启动Docker
开机自动启动Docker:关闭自启动用 disable
sudo systemctl enable docker
启动Docker:
sudo systemctl start docker.service
linux中systemctl详细理解及常用命令
检查一下docker启动完成:第二个命令的第二行,出现hello-world镜像仓库,是因为前面测试开启的,正常未开启仓库应该只有第一行
3 配置Docker镜像
- 创建文件
/etc/docker/daemon.json
文件,获取文件操作权限,然后添加镜像地址,参考:docker 配置国内镜像地址
{
"registry-mirrors": [
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn"
]
}
- 重启docker,重新加载配置,并使用docker info 命令查看
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo docker info
可以看到某个部分有下面的信息:
接下来就可以用docker pull xxx
来拉取镜像了。