0%

Docker的安装与使用

记录docker的安装部署和日常使用命令

准备工作

确认系统版本

1
2
cat /etc/redhat-release 
CentOS Linux release 7.7.1908 (Core)

配置yum

1
2
3
4
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache

如果出现dns解析问题,在网卡配置加上dns服务器配置
vi /etc/sysconfig/network-scripts/ifcfg-eth0
文末添加

1
2
DNS1=8.8.8.8
DNS2=8.8.4.4

service network restart

安装Docker

1
2
3
4
5
6
7
8
9
10
11
12
13
14
sudo yum update
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2

# 添加docker的yum源
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo

# 更新yum
sudo yum update
# 安装docker
sudo yum install docker-ce

配置docker

1
2
3
4
5
6
7
8
# 加入 docker 用户组命令
sudo usermod -aG docker geolab
# 开机启动
sudo systemctl enable docker
# 启动docker
sudo systemctl start docker
# 验证docker
sudo docker run hello-world

配置阿里云镜像加速

关于加速器的地址,登陆阿里云控制台获取
添加以下内容

1
2
3
4
5
6
7
8
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["address"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

1
2
3
4
5
6
7
8
# 重启docker
systemctl daemon-reload
systemctl restart docker
# 将 --registry-mirror 加入到你的 Docker 配置文件
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io

# 重启docker
service docker restart

docker常用命令

问题