• docker run 的常用参数用法

    docker run 的常用参数用法

    Docker run 作为运行容器的直接入口,命令参数相当丰富,使用它可以启动容器,使容器拥有自己的文件系统、网络以及关系进程树。

    Docker run 命令基本结构:

    1. $ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]

    为了更好理解,我们将参数分为以下几类:

    1. 容器管理:
      • 后台程序和前台交互程序
      • 器的定义
    2. 网络设置
    3. CPU和内存的runtime
    4. 权限和LXC配置
    1. -a, --attach=[] Attach to STDIN, STDOUT or STDERR
    2. --add-host=[] Add a custom host-to-IP mapping (host:ip)
    3. --blkio-weight=0 Block IO (relative weight), between 10 and 1000
    4. -c, --cpu-shares=0 CPU shares (relative weight)
    5. --cap-add=[] Add Linux capabilities
    6. --cap-drop=[] Drop Linux capabilities
    7. --cgroup-parent= Optional parent cgroup for the container
    8. --cidfile= Write the container ID to the file
    9. --cpu-period=0 Limit CPU CFS (Completely Fair Scheduler) period
    10. --cpu-quota=0 Limit the CPU CFS quota
    11. --cpuset-cpus= CPUs in which to allow execution (0-3, 0,1)
    12. --cpuset-mems= MEMs in which to allow execution (0-3, 0,1)
    13. -d, --detach=false Run container in background and print container ID
    14. --device=[] Add a host device to the container
    15. --dns=[] Set custom DNS servers
    16. --dns-search=[] Set custom DNS search domains
    17. -e, --env=[] Set environment variables
    18. --entrypoint= Overwrite the default ENTRYPOINT of the image
    19. --env-file=[] Read in a file of environment variables
    20. --expose=[] Expose a port or a range of ports
    21. -h, --hostname= Container host name
    22. --help=false Print usage
    23. -i, --interactive=false Keep STDIN open even if not attached
    24. --init= Run container following specified init system container method (systemd)
    25. --ipc= IPC namespace to use
    26. -l, --label=[] Set meta data on a container
    27. --label-file=[] Read in a line delimited file of labels
    28. --link=[] Add link to another container
    29. --log-driver= Logging driver for container
    30. --log-opt=[] Log driver options
    31. --lxc-conf=[] Add custom lxc options
    32. -m, --memory= Memory limit
    33. --mac-address= Container MAC address (e.g. 92:d0:c6:0a:29:33)
    34. --memory-swap= Total memory (memory + swap), '-1' to disable swap
    35. --name= Assign a name to the container
    36. --net=bridge Set the Network mode for the container
    37. --oom-kill-disable=false Disable OOM Killer
    38. -P, --publish-all=false Publish all exposed ports to random ports
    39. -p, --publish=[] Publish a container's port(s) to the host
    40. --pid= PID namespace to use
    41. --privileged=false Give extended privileges to this container
    42. --read-only=false Mount the container's root filesystem as read only
    43. --restart=no Restart policy to apply when a container exits
    44. --rm=false Automatically remove the container when it exits
    45. --security-opt=[] Security Options
    46. --sig-proxy=true Proxy received signals to the process
    47. -t, --tty=false Allocate a pseudo-TTY
    48. -u, --user= Username or UID (format: <name|uid>[:<group|gid>])
    49. --ulimit=[] Ulimit options
    50. --uts= UTS namespace to use
    51. -v, --volume=[] Bind mount a volume
    52. --volumes-from=[] Mount volumes from the specified container(s)
    53. -w, --workdir= Working directory inside the container