在Debian系统中管理Docker容器,可按照如下步骤执行:
更新软件包索引
sudo apt update
安装必备软件包
sudo apt install apt-transport-https ca-certificates curl software-properties-common
导入Docker官方的GPG密钥
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
配置Docker的APT源
echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.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 update sudo apt install docker-ce docker-ce-cli containerd.io
启动Docker服务并设置开机启动
sudo systemctl start docker sudo systemctl enable docker
显示运行中的容器:
docker ps
展示所有容器(含已停止的):
docker ps -a
新建并运行一个容器:``` docker run -it --name my_container ubuntu bash
其中 -it 表示交互模式,--name 定义容器名,ubuntu 是基础镜像,bash 是进入容器后默认运行的命令。
停止指定容器:
docker stop my_container
启动已停止的容器:
docker start my_container
docker rm my_container
检查Docker版本
docker --version
获取Docker详细信息
docker info
监控Docker服务状态
sudo systemctl status docker
列出本地镜像
docker images
下载远程镜像
docker pull ubuntu
上传镜像至仓库
docker push yourusername/yourimage:tag
可通过编辑 /etc/docker/daemon.json 来调整Docker守护进程的参数。例如,设定存储驱动及日志级别。
{
"storage-driver": "overlay2",
"log-level": "info"
}修改完成后,需重启Docker服务使改动生效:
sudo systemctl restart docker
依照上述指导,您便能在Debian系统上高效地操控Docker容器了。