这篇文章上次修改于 894 天前,可能其部分内容已经发生变化,如有疑问可询问作者。
title: "DOCKER.md"
author: "andy"
description: "description information"
date: "2016-09-28"
lastmod: "2023-11-28"
docker 命令操作笔记
docker在线安装: apt install docker.io
docker离线安装:
tar -zxvf docker-18.06.3-ce.tgz
cp docker/* /usr/bin/
dockerd &
docker info
docker run hello-world # Hello from Docker!
docker search ubuntu
docker pull --help
docker images --help
docker update --help
docker run --help
docker rm --help
docker rmi --help
docker attach --help
docker exec --help
docker inspect --help
-- 说明操作容器ID和操作容器name效果一样
帮助命令:docker version
帮助命令:docker info
帮助命令:docker --help
停止容器: docker stop 095815a83b5a
启动容器: docker start 095815a83b5a
重启容器: docker restart ubuntuexe
进入容器: docker exec -it 095815a83b5a /bin/bash
删除容器: docker rm -f 095815a83b5a
删除镜像: docker rmi -f imageID
删除多个镜像:docker rmi $(docker images -q ubuntu)
删除多个容器:docker rm -f $(docker ps -a -q)
拉取镜像:docker pull debian
拉取镜像:docker pull ubuntu:18.04 # xxx[:TAG] ubuntu:18.04 ubuntu:latest
搜索镜像:docker search --limit 5 redis
导出镜像:docker save -o ubuntu.tar ubuntu:18.04
导入镜像:docker load < ubuntu.tar
镜像打标签:docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
容器详情: docker inspect ubuntuexe
容器进程: docker top ubuntuexe
容器日志: docker logs ubuntuexe
运行容器:docker exec -it ubuntuexe/bin/bash # 新开bash,exit退出原容器不会结束
附上容器:docker attach ubuntuexe # 登入原有bash,exit退出会退出停止原有容器
提交容器:docker commit ubuntuexe/ubuntu
保存镜像:docker save imageid > /tmp/ubuntu.tar
加载镜像:docker load < /tmp/ubuntu.tar
导出容器:docker export containerid > /tmp/ubuntu.tar
导入容器:docker import - exe/ubuntu:latest < < /tmp/ubuntu.tar
容器传输:docker cp .vimrc ubuntuexe:/root/.vimrc
容器传输:docker cp ubuntuexe:/root/READEME.md READEME.md
运行容器:docker run --privileged=true -it ubuntu:18.04 /bin/bash
运行容器:docker run --privileged=true --restart=always -v /opt:/opt -v -p 8022:22 -itd ubuntu:18.04 /bin/bash
已经过运行的容器设置自启动: docker update --restart=always ubuntuname
自动启动 : docker update --restart=always d5c440e6d44f
更新 CPU 共享数量: docker update --cpu-shares 512 f361b7d8465
更新容器的重启策略: docker update --restart=always f361b7d8465
更新容器内存: docker update -m 500M f361b7d8465
-- docker run -d启动的容器和--restart=always每次进入退出直接 docker attach <container ID> 即可。
-- # ps -ef | grep exe_ | grep -v grep | awk '{print $2}' | xargs kill -9
-- # (./bin/exe_analyse &) && (./bin/exe_inotify &) && (./bin/exe_insert &) && (./bin/exe_python &)
1.在/usr/lib/systemd/system/目录下创建docker.service文件
sudo systemctl enable docker #设置docker开机自启动
sudo systemctl start docker #启动docker.service服务
systemctl daemon-reload ## 2.重新加载unit配置文件
systemctl start/stop docker ## 3.启动/停止docker服务
systemctl enable/disable docker ## 4.开机自启/取消开机自启 docker 服务
systemctl list-units --type=service # 查看已启动的服务
systemctl list-unit-files | grep enable # 查看是否设置开机启动
用户和属组可以不用设置
服务管理:sudo systemctl enable docker #设置docker开机自启动
服务管理:sudo systemctl start docker #启动docker.service服务
服务管理:sudo groupadd docker
服务管理:sudo usermod -aG docker $USER
vim /usr/lib/systemd/system/docker.service
vim /etc/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
vim /etc/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
Docker 命令大全 --容器生命周期管理
docker docker run
docker start/stop/restart
docker kill
docker rm
docker pause/unpause
docker create
docker exec
--docker 容器操作
docker ps
docker inspect
docker top
docker attach
docker events
docker logs
docker wait
docker export
docker port
docker stats
--docker 容器rootfs命令
docker commit
docker cp
docker diff
--docker 镜像仓库
docker login
docker pull
docker push
docker search
--docker 本地镜像管理
docker images
docker rmi
docker tag
docker build
docker history
docker save
docker load
docker import
--docker 详情版本info|version
docker info
docker version
Docker常用命令大全(万字详解)
启动docker: systemctl start docker
启动docker: systemctl start docker
停止docker: systemctl stop docker
停止docker: systemctl stop docker
重启docker: systemctl restart docker
重启docker: systemctl restart docker
查看docker状态: systemctl status docker
查看docker状态: systemctl status docker
开机启动: systemctl enable docker
查看docker概要信息: docker info
查看docker概要信息: docker info
查看docker总体帮助文档: docker --help
查看docker总体帮助文档: docker --help
查看docker命令帮助文档: docker 具体命令 --help
查看docker命令帮助文档: docker 具体命令 --help
如果你不指定一个镜像的版本标签,docker 将默认使用 xxx:latest 镜像
官方搜索网址:https://hub.docker.com/
docker images
docker images -a
docker images -q
docker search [OPTIONS] 镜像名字
[root@docker ~]# docker search mysql
[root@docker ~]# docker search mysql
mysql/mysql-server Optimized MySQL Server Docker images. Create… 917 [OK] 12345
docker pull 某个XXX镜像名字[:TAG] 等价于:docker pull 镜像名字:latest
docker search --limit 5 redis
docker pull 某个XXX镜像名字
docker system df 查看镜像/容器/数据卷所占的空间
docker rmi -f 镜像ID
docker rmi -f 镜像名1:TAG 镜像名2:TAG
docker rmi -f $(docker images -qa) docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
docker run -it centos /bin/bash
docker ps [OPTIONS] docker start 容器ID或者容器名
docker ps [OPTIONS] docker start 容器ID或者容器名
docker ps -a -q :查询进行的容器ID
docker stop 容器ID或者容器名
docker kill 容器ID或容器名
docker rm 容器ID
[root@docker ~]# docker rm -f $(docker ps -a -q)
[root@docker ~]# docker rm -f $(docker ps -a -q)
[root@docker ~]# docker ps -a -q | xargs docker rm
[root@docker ~]# docker ps -a -q | xargs docker rm
docker run -d 容器名
[root@docker ~]# docker run -d centos
[root@docker ~]# docker run -it redis
[root@docker ~]# docker run -d redis
docker logs 容器ID
[root@docker ~]# docker ps
[root@docker ~]# docker logs 94b
docker top 容器ID
[root@docker ~]# docker top 94b
[root@docker ~]# docker top 94b
docker inspect 容器ID
docker exec -it 容器ID bashShell
[root@docker ~]# docker exec -it 94b /bin/bash
[root@docker ~]# docker exec -it 94b /bin/bash
[root@docker ~]# docker exec --help
docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
docker start 容器ID
docker attach 容器ID <退出之后自动stop容器>
docker cp 容器ID:容器内路径 目的主机路径
[root@docker /]# docker cp 3065f084c80d:a.txt a.txt
docker export 容器ID > 文件名.tar
docker import - 镜像用户/镜像名:镜像版本号 < 文件名.tar
[root@docker /]# docker export 3065f084c80d > centos.tar.gz
[root@docker /]# cat centos.tar.gz | docker import - xiaobear/centos:8.8
[root@docker /]# docker import - xiaobear/centos:8.8 < centos.tar.gz
[root@docker /]# docker images
没有评论
博主关闭了评论...