在Ubuntu上运行Docker的步骤如下:
首先,确保你的Ubuntu系统是最新的:
sudo apt update sudo apt upgrade -y 安装一些必要的软件包,以便apt可以通过HTTPS使用仓库:
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - 将Docker的仓库添加到APT源列表中:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" 更新APT包索引以包含Docker包:
sudo apt update 安装Docker社区版及其相关组件:
sudo apt install docker-ce docker-ce-cli containerd.io -y 运行一个测试容器来验证Docker是否正确安装:
sudo docker run hello-world 如果一切正常,你应该会看到一条消息,说明你的Docker引擎正在运行。
你可以使用以下命令来管理Docker服务:
sudo systemctl start docker sudo systemctl stop docker sudo systemctl restart docker sudo systemctl enable docker 如果你需要配置Docker守护进程,可以编辑/etc/docker/daemon.json文件。例如,设置Docker守护进程的存储驱动:
{ "storage-driver": "overlay2" } 然后重启Docker服务以应用更改:
sudo systemctl restart docker 现在你可以开始使用Docker了。例如,拉取一个镜像并运行一个容器:
sudo docker pull ubuntu sudo docker run -it ubuntu bash 通过以上步骤,你就可以在Ubuntu上成功安装和运行Docker了。