docker命令

更新于 2024-08-05

常用命令

#Dockerfile构建
docker build --tag xxxxx .

#拷贝文件到容器
docker cp ./ xxxx:/home/xxx

#提交容器为镜像
docker commit 容器名 镜像名

docker ps -a # docker container ls -a
docker stop|start xxx
docker images
docker image rm xxxx

#运行容器
docker run -id[ --name xxxx][ --restart always][ -p aaa:bbb][ -v ccc:ddd] [image] /bin/bash

docker exec -it xxxx /bin/bash

启动docker

systemctl status docker
sudo service docker start

docker自动启动

systemctl edit docker

systemctl daemon-reload

systemctl enable docker

[Service]
Restart=always

升级docker

# 卸载docker
sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine

# 安装docker
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
    "registry-mirrors": [
        "https://dockerproxy.com",
        "https://docker.mirrors.ustc.edu.cn",
        "https://docker.nju.edu.cn"
    ]
}
EOF
systemctl daemon-reload
systemctl restart docker

超级权限

docker run --privileged

自动启动

docker run --restart always