Introduction
要使用命令行,需要执行
apt install docker.io
或者snap install docker
配置
修改Docker配置本地镜像与容器的存储位置
openwrt 里 docker 数据迁移问题 更改 Docker Root Dir
安装
linux
1 2 3 4 5
| apt install docker docker.io
OR
snap install docker
|
docker-compose
docker-compose安装,解决Warning: the “docker“ command appears to already exist on this system.3的问题
1 2 3 4
| curl -SL https://github.com/docker/compose/releases/download/v2.17.2/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose docker-compose --version
|
服务管理
Openwrt
1 2 3 4
| /etc/init.d/dockerd start /etc/init.d/dockerd stop /etc/init.d/dockerd restart /etc/init.d/dockerd status
|
linux
命令
run
参数解释
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
- -d:选项是让容器以守护态
- -p: 指定端口映射,格式为:主机(宿主)端口:容器端口
- –volume , -v: 绑定一个卷,前者为宿主文件目录,后者为容器目录
- –restart:no,on-failure[:times],always,unless-stopped 说明
更新参数为:docker update --restart=always [容器名]
例子:
1
| docker run -d --restart=always -v /etc/alist:/opt/alist/data -p 5244:5244 -e PUID=0 -e PGID=0 -e UMASK=022 --name="alist" xhofe/alist:latest
|
常见操作
命令 |
说明 |
docker ps |
查看运行中的容器 |
docker images |
查看镜像 |
docker rm 容器id |
删除指定容器 |
docker container update --restart=always 容器id |
|
docker inspect 容器id |
查看镜像的元数据 |
docker load -i {image_name}.tar |
导入镜像 |
docker save : |
gzip > _.tar.gz |
gunzip -c 文件名.tar.gz |
docker load |
docker stop 容器id |
停止当前正在运行的容器 |
docker exec -it 44fc0f0582d9 /bin/bash |
进入容器终端 |
|
|
|
|
|
|
|
|
|
|
|
|
docker镜像保存加载导入导出
参考
docker常用命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| docker info docker version
docker 命令 --help
docker images docker search docker pull docker rmi
docker run 镜像id docker ps 列出所有运行的容器 docker container list docker rm 容器id docker rm -f $(docker ps -aq) docker ps -a -q|xargs docker rm
docker start 容器id docker restart 容器id docker stop 容器id docker kill 容器id
exit ctrl +P +Q
docker run -d 镜像名 docker logs docker top 容器id docker inspect 容器id docker exec docker attach docker cp 容器id:容器内路径 主机目的路径
|
docker命令大全
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
| docker attach docker build docker builder docker builder prune docker checkpoint docker checkpoint create docker checkpoint ls docker checkpoint rm docker commit docker config docker config create docker config inspect docker config ls docker config rm docker container docker container prune docker context docker context create docker context export docker context import docker context inspect docker context ls docker context rm docker context update docker context use docker cp docker create docker diff docker events docker exec docker export docker history docker image docker image inspect docker image ls docker image prune docker image rm docker images docker import docker info docker inspect docker kill docker load docker login docker logout docker logs docker manifest docker manifest annotate docker manifest create docker manifest inspect docker manifest push docker manifest rm docker network docker network connect docker network create docker network disconnect docker network inspect docker network ls docker network prune docker network rm docker node docker node demote docker node inspect docker node ls docker node promote docker node ps docker node rm docker node update docker pause docker plugin docker plugin create docker plugin disable docker plugin enable docker plugin inspect docker plugin install docker plugin ls docker plugin push docker plugin rm docker plugin set docker plugin upgrade docker port docker ps docker pull docker push docker rename docker restart docker rm docker rmi docker run docker save docker search docker secret docker secret create docker secret inspect docker secret ls docker secret rm docker service docker service create docker service inspect docker service logs docker service ls docker service ps docker service rm docker service rollback docker service scale docker service update docker stack docker stack deploy docker stack ls docker stack ps docker stack rm docker stack services docker start docker stats docker stop docker swarm docker swarm ca docker swarm init docker swarm join docker swarm join-token docker swarm leave docker swarm unlock docker swarm unlock-key docker swarm update docker system docker system df docker system events docker system info docker system prune docker tag docker top docker trust docker trust inspect docker trust key docker trust key generate docker trust key load docker trust revoke docker trust sign docker trust signer docker trust signer add docker trust signer remove docker unpause docker update docker version docker volume docker volume create docker volume inspect docker volume ls docker volume prune docker volume rm docker wait
|
常见问题
openwrt容器无法访问网络
方法一:重建网桥
重建网桥docker0
方法二:只用主机共享网络
解决docker容器无网络
使用主机网络
1
| docker run -it --rm --network=host centos /bin/bash
|
Reference
Docker常用命令,命令大全