安装docker和docker-compose
安装docker和docker-compose
以下为debian安装方式,其他系统类似
安装docker的官网地址:https://docs.docker.com/engine/install/debian/
安装docker
卸载旧版本
sudo apt-get remove docker docker-engine docker.io containerd runc
添加仓库
- 更新仓库,安装必要的软件包
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg lsb-release
- 添加gpg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
- 设置仓库
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
安装docker核心
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
安装完成之后,查看docker版本:
docker versioin
解决docker权限问题
最后面几行可能会出现权限报错,错误显示如下:
Got permission denied while trying to connect to the Docker daemon socket at...
解决办法如下:
sudo groupadd docker #添加docker用户组
sudo gpasswd -a $USER docker #将登陆用户加入到docker用户组中
newgrp docker #更新用户组
安装docker-compose
安装docker-compose的官方地址:https://docs.docker.com/compose/install/compose-plugin/#install-using-the-repository
查看需要下载的版本号
先从github上查询最新的docker-compose版本,替换下文中的2.6.0
版本号:https://github.com/docker/compose/releases
下载docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/v2.6.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
授权
sudo chmod +x /usr/local/bin/docker-compose
检查docker-compose版本
docker-compose version