1、docker命令
>brew cask install docker
#docker 安装
>docker run ubuntu:15.10 /bin/echo "Hello world"
#运行某容器
>docker run -i -t ubuntu:15.10 /bin/bash
#运行交互式的容器
#-t:在新容器内指定一个伪终端或终端。
#-i:允许你对容器内的标准输入 (STDIN) 进行交互。
>docker run -d ubuntu:15.10 /bin/sh -c "while true; do echo hello world; sleep 1; done"
#以进程方式运行容器
>docker ps
#查看正在运行的容器
>docker logs containerID/containerName
#查看容器内的标准输出
>docker stop containerID/containerName;
#停止容器
>docker ps -a/docker rm containerID
#删除容器
>docker logs -f -t --tail 10 containerID/containerName
#查看某容器日志结尾10条
#sudo docker logs -f -t --tail 行数 容器名
#docker-compose 时区修改
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
删除镜像
images和container。其中images很好理解,跟平常使用的虚拟机的镜像一个意思,相当于一个模版,而container则是images运行时的的状态。docker对于运行过的image都保留一个状态(container),可以使用命令docker ps来查看正在运行的container,对于已经退出的container,则可以使用docker ps -a来查看。 如果你退出了一个container而忘记保存其中的数据,你可以使用docker ps -a来找到对应的运行过的container使用docker commit命令将其保存为image然后运行。
回到之前的问题,由于image被某个container引用(拿来运行),不将这个引用的container销毁(删除),那image肯定是不能被删除。
故,引用某个镜像的容器删除完毕后,才可以使用docker rmi imageID命令来删除镜像.
>docker images
#查看已安装镜像
>docker rmi imageID
#删除某镜像
2、docker删除无用容器及镜像组合命令:
docker ps -a | grep "Exited" | awk '{print $1 }'|xargs docker stop
docker ps -a | grep "Exited" | awk '{print $1 }'|xargs docker rm
docker images|grep none|awk '{print $3 }'|xargs docker rmi
Stop and remove all docker containers and images
List all containers (only IDs) docker ps -aq.
Stop all running containers. docker stop $(docker ps -aq)
Remove all containers. docker rm $(docker ps -aq)
Remove all images. docker rmi $(docker images -q)
#docker空间查询
➜ laradock git:(master) ✗ docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 11 0 2.962GB 2.962GB (100%)
Containers 0 0 0B 0B
Local Volumes 146 0 26.84MB 26.84MB (100%)
Build Cache 0 0 0B 0B
#docker system prune 清理无用的容器及镜像,危险!!
➜ laradock git:(master) ✗ docker system prune
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all dangling build cache
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B
#docker system prune -a 清理所有的容器及镜像,危险!!
✗ docker system prune -a
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all images without at least one container associated to them
- all build cache
Are you sure you want to continue? [y/N] y
Deleted Images:
3、docker-compose
docker-compose up -d nginx redis mysql phpmyadmin //编排服务;
docker-compose restart mysql; //重启
docker-compose ps -a; //查看正在运行服务;
docker-compose stop mysql; //停止某项服务;
docker-compose run container_name bash //clone当前容器,修改内容与当前运行容器无关
docker-compose build mysql; //重新配置某项服务
docker-compose exec mysql env LANG=C.UTF-8 bash; //使用中文环境打开容器
docker-compose exec container_name bash //直接修改容器文件