Title: "[[Docker]]"
status: DONE
tags:
- Docker
- NOTE
Author:
- AllenYGY
created: 2024-02-22T11:12
updated: 2024-03-21T22:57
docker image ls
docker search [image]
docker search nginx
docker pull[image]
docker push[image]
docker push geekhour/hello-docker:latest
docker save [image] -o FILE
docker save [image] > FILE
docker save geekhour/hello-docker:latest
docker load -i FILE
docker load -i hello-docker.tar
docker history[image]
docker rmi [image]
docker image rm [image]
docker image prune
docker import [URL/FILE]
docker commit [container][image]
docker create [image]
docker run [image]
docker start [container]
docker stop [container]
docker restart [container]
docker ps
docker container ls
docker ps -a
docker container ls -a
docker exec -it [container] bash
docker attach [container]
docker export [container] -o FILE
docker export [container] > FILE
docker import FILE
docker logs [container]
docker rm [container]
docker container rm [container]
docker port [container]
docker top [container]
docker cp [FILE] [container]:[PATH]
docker diff [container]
docker stats [container]
docker volume create [volume]
docker volume ls
docker volume inspect [volume]
docker volume rm [volume]
docker volume prune
docker network ls
docker network inspect [network]
docker network create [network]
docker network rm [network]
docker network connect [network] [container]
docker network disconnect [network] [container]
docker plugin ls
docker plugin install [plugin]
docker plugin enable [plugin]
docker plugin disable [plugin]
docker plugin rm [plugin]
docker run [options] image [command][arg...]
docker run -d -p[hostPost]:[containerPort] -e [key=value] -w[PATH] --name[name][image]
docker run --name[name][image]
docker run -d[image]
docker run -p[hostPort]:[containerPort][image]
docker run -P[image]
docker run -e[key=value][image]
docker run -w[PATH][image]
docker run [image][command]
docker run -it nginx:latest /bin/bash
使用镜像nginx:latest 来启动一个容器,并在容器内执行交互式 bash shell
docker run -it -p 3316:3306 -v /data:/data -d mysql:latest
创建⼀个 mysql 容器,后台模式启动,主机 3316 端⼝ 映射到容器 3306 端⼝,主机 /data ⽬录映射到容器 /data ⽬录
docker info
docker version
docker--help
docker[command]--help
docker login/logout
# 基础镜像设置
FROM [base_image]
# 指定基础镜像,必须为Dockerfile的第一条指令;
# 文件添加指令
ADD <src>... <dest>
# 用于将文件复制到镜像中,源可以是URL或者本地文件,也可以是一个压缩文件(自动解压)
# 文件复制指令
COPY [--chown=<user>:<group>] <src>... <dest>
# 用于将文件复制到镜像中,源只能是本地文件
# 工作目录指令
WORKDIR /path/to/workdir
# 用于指定工作目录,可以使用多个WORKDIR指令,如果使用相对路径,则是相对于上一条WORKDIR指令的路径
# 环境变量指令
ENV <key> <value>
ENV <key1>=<value1> <key2>=<value2>...
# 用于设置环境变量
# 执行命令指令
CMD ["executable","param1","param2"]
CMD command param1 param2
# 用于指定默认的容器主进程,每个Dockerfile中只能有一条CMD指令,如果有多条,则只有最后一条会生效
# 卷挂载指令
VOLUME ["/path/to/volume"]
VOLUME ["/path1", "/path2"...]
# 用于定义匿名卷,持久化数据