停止container
docker stop xxxx
延迟停止
docker stop -t 10 xxxx
列出container
docker ps [-a]所有,不管在不在running [-q]只列出id | xargs docker rm列出来的全删了
删除container
docker rm -f xxxx
删除image
docker rmi -f my-image
build image
docker build -t our-web-server -f web-server.Dockerfile .
启动容器
docker run [-d]后台启动,不占用terminal [–name our-web-server]为container命名 [-p 5001:5000]端口映射,主机端口:container端口 our-web-server
查看log
docker logs our-web-server/xxxx
创建并立即删除,同时执行命令,这个file只存在于container内部,当container被删除,file自然也不在
docker run --rm --entrypoint sh ubuntu -c “echo ‘Hello there.’ > /tmp/file && cat /tmp/file”
如果要文件在外部,需要卷的挂载,mount volume.这时候文件在外部位置是/tmp/container/file。这里是目录映射,也可以文件映射 -v /tmp/change_file:/tmp/file 这样外部就是/tmp/change_file
docker run --rm --entrypoint sh -v /tmp/container:/tmp …
系统修剪,去除无用的image
docker system prune
container运行太慢
docker stats xxx 查看IO
docker exec [-i]交互 [-t]-tty xxx sh然后执行命令,会一直运行命令
docker top xxx
docker inspect xxx | less 用json格式显示并分页