zoukankan      html  css  js  c++  java
  • docker中的小技巧

    这篇文章下的指令都是我在工作年中常用到的一些操纵docker中container的小技巧。

    1. 如果只是做短暂的容器实验,可以通过在命令中指定 --rm 来避免清理工作的负担。容器进入退出状态时,就会自动删除。
      例如,下面的命令会将一个新的busyboy 容器显示的消息写到屏幕上并在容器退出时立即被删除:
            docker run --rm --name auto-exit-test busybox:latest echo Hello World  
    
    
    1. 使用--read-only标志创建容器时,会将挂载的容器文件系统设置为只读,防止容器被修改

    2. 容器重启策略,即再容器创建时设置--restart标志,将有助于系统出现故障时进行自动恢复。

    docker build -t friendlyname .  # Create image using this directory's Dockerfile
    docker run -p 4000:80 friendlyname  # Run "friendlyname" mapping port 4000 to 80
    docker run -d -p 4000:80 friendlyname         # Same thing, but in detached mode
    docker container ls                                # List all running containers
    docker container ls -a             # List all containers, even those not running
    docker container stop <hash>           # Gracefully stop the specified container
    docker container kill <hash>         # Force shutdown of the specified container
    docker container rm <hash>        # Remove specified container from this machine
    docker container rm $(docker container ls -a -q)         # Remove all containers
    docker image ls -a                             # List all images on this machine
    docker image rm <image id>            # Remove specified image from this machine
    docker image rm $(docker image ls -a -q)   # Remove all images from this machine
    docker login             # Log in this CLI session using your Docker credentials
    docker tag <image> username/repository:tag  # Tag <image> for upload to registry
    docker push username/repository:tag            # Upload tagged image to registry
    docker run username/repository:tag                   # Run image from a registry
    
    docker stack ls                                            # List stacks or apps
    docker stack deploy -c <composefile> <appname>  # Run the specified Compose file
    docker service ls                 # List running services associated with an app
    docker service ps <service>                  # List tasks associated with an app
    docker inspect <task or container>                   # Inspect task or container
    docker container ls -q                                      # List container IDs
    docker stack rm <appname>                             # Tear down an application
    
  • 相关阅读:
    探索c#之一致性Hash详解
    Redis系列(三)-Redis发布订阅及客户端编程
    Redis系列(二)-Hredis客户端设计及开源
    关于电脑操作一些高效的方法工具
    探索c#之递归APS和CPS
    探索C#之系列目录导航
    探索c#之不可变数据类型
    SOA相关资料整理分享
    探索c#之尾递归编译器优化
    探索c#之函数创建和闭包
  • 原文地址:https://www.cnblogs.com/Ethan2lee/p/7471401.html
Copyright © 2011-2022 走看看