docker 基础命令
列出Docker本地所有镜像
docker images下载镜像
# 下载ubuntu镜像
docker pull ubuntu
# 下载mysql镜像
docker pull mysql停止和启动容器服务
[root@localhost ~]# systemctl stop docker
[root@localhost ~]# systemctl start docker下载并运行 hyperf/hyperf 镜像,并将镜像内的项目目录绑定到宿主机的 /tmp/skeleton 目录
docker run -v /data/code:/data/code -p 80:9501 -it --entrypoint /bin/sh hyperf/hyperf:latest
docker run -v 主机路径:容器里面的路径 -p 主机端口:容器端口 -it --entrypoint /bin/sh (hyperf/hyperf:latest 镜像名:最新版本)查看运行中的容器
docker ps查看本地镜像: (参数-a 表示所有)
docker ps -a进入容器
docker exec -it f54fc094edb2 /bin/bash当容器中执行exit时自动重启
--restart=always关闭容器
docker stop id删除容器
docker rm -f 容器名- 通过容器名查询挂载配置信息
docker inspect 容器名| grep Mounts -A 20
➜ ~ docker inspect my_hyperf | grep Mounts -A 20
"Mounts": [
{
"Type": "bind",
"Source": "/data/docker/code/fhx",
"Destination": "/data/fhx",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
},
{
"Type": "bind",
"Source": "/data/docker/code/wuloves",
"Destination": "/data/wuloves",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
"Config": {
"Hostname": "8898fabf14e8",
"Domainname": "",危险命令, 切勿在生产环境使用, 且使用前记得反复核对当前连接且关闭当前和非实验环境的连接
停止所有容器
docker stop $(docker ps -a -q)
删除所有容器
docker rm $(docker ps -a -q)
删除所有镜像
docker rmi `docker images -a -q`- 当容器中没有
/bin/bash时, 使用直接的sh就可以
[root@localhost ~]# docker exec -it etcd1 /bin/bash
OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory": unknown
[root@localhost ~]# docker exec -it etcd1 sh
/ #