记录一些平时自己维护时用的比较多的Docker命令
- 添加hosts文件
 - 
    
docker run --add-host="localA:127.0.0.1" - 显示所有images
 - 
    
docker images - 打包镜像
 - 
    
docker build -t docker-whale .command takes the Dockerfile in the current directory, and builds an image called docker-whale on your local machine.命令最后有一点
 - 删除镜像
 - 
    
docker rmi - 删除容器
 - 
    
docker rm - docker run参数
 - 
    
- -t flag assigns a pseudo-tty or terminal inside the new container.
 - -i flag allows you to make an interactive connection by grabbing the standard input (STDIN) of the container.
 - -d flag runs the container in the background (to daemonize it).
 - -P flag maps any required network ports inside the container to your host. This lets you view the web application.
 
 - 给正在运行的容器添加端口映射
 - 
    
docker port jolly_sinoussi 5000 0.0.0.0:80 - 查看正在运行的容器
 - 
    
docker ps - 查看所有容器
 - 
    
docker ps a - 重启容器
 - 
    
docker restart - 查看容器输出到stdin、stderr的日志
 - 
    
docker logs - 查看容器的详细配置文件
 - 
    
docker inspect - 将容器打包成镜像
 - 
    
docker commit containerid image_id - 进入正在运行的容器
 - 
    
docker exec -ti <docker_name> /bin/bash或者
docker attach - 导出镜像
 - 
    
docker save myimage:latest | gzip > myimage_latest.tar.gz - 导入镜像
 - 
    
docker load -i myimage_latest.tar.gz或者
docker load < myimage_latest.tar.gz - 清理镜像
 - 
    
docker system prune命令可以用于清理磁盘,删除关闭的容器、无用的数据卷和网络,以及dangling镜像(即无tag的镜像)。
docker system prune -a命令清理得更加彻底,可以将没有容器使用Docker镜像都删掉。
 - 导出本机上所有带tag的镜像
 - 
    
docker save $(docker images --format ':') -o allinone.tar - 挂载本地文件夹
 - 
    
-v /src/webapp:/dst/webapp - 重启策略
 - 
    
--restart always/unless-stopped/no/on-failure - 参考
 - Docker官方文档
 
      
    
      
留下评论