docker 常用命令

2016-11-16 Frank 服务器

  • 容器启动

    docker start name
    
  • 容器停止

    docker stop name
    
  • 查看新创建的镜像的详细信息

    docker inspect frank/docker_web_app:alpine
    
  • 备份容器

    docker images
    docker save -o ~/ocserv.tar learn/ing
    
  • 恢复容器

    systemctl enable docker.service
    systemctl start docker
    docker load -i ~/ocserv.tar
    docker images
    
  • 迁移Docker容器

    scp -P 225 root@ss1.liangcuntu.com:/root/ocserv.tar ~
    
  • 更改容器目录(通过软连接的方式)

    cd /var/lib
    mv docker /new_dir/
    ln -s /new_dir/docker docker
    
  • 制作镜像并推送到仓库

    sudo docker build -t frank/test .
    sudo docker push registry.cn-beijing.aliyuncs.com/frank/test
    
  • 镜像删除

    docker rmi IMAGE_ID
    

The commands below have become hacks as Docker becomes more developed. The current best practice is

docker system prune

This will remove:

  • all stopped containers
  • all volumes not used by at least one container
  • all networks not used by at least one container
  • all dangling images
    之后删除Tag为none的镜像

    sudo docker rmi $(sudo docker images | grep "none" | awk '{print $3}')
    
  • 运行容器

    sudo docker run --name test -p 2005:2005 -d registry.cn-beijing.aliyuncs.com/frank/test
    
  • 进入容器

    sudo docker exec -it test sh
    

从主机复制到容器

sudo docker cp host_path containerID:container_path

从容器复制到主机

sudo docker cp containerID:container_path host_path

标签: docker

发表评论 登录

Top