flags.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "path/filepath"
  6. "runtime"
  7. "github.com/docker/docker/opts"
  8. flag "github.com/docker/docker/pkg/mflag"
  9. )
  10. var (
  11. dockerCertPath = os.Getenv("DOCKER_CERT_PATH")
  12. dockerTlsVerify = os.Getenv("DOCKER_TLS_VERIFY") != ""
  13. )
  14. func init() {
  15. if dockerCertPath == "" {
  16. dockerCertPath = filepath.Join(getHomeDir(), ".docker")
  17. }
  18. }
  19. func getHomeDir() string {
  20. if runtime.GOOS == "windows" {
  21. return os.Getenv("USERPROFILE")
  22. }
  23. return os.Getenv("HOME")
  24. }
  25. var (
  26. flVersion = flag.Bool([]string{"v", "-version"}, false, "Print version information and quit")
  27. flDaemon = flag.Bool([]string{"d", "-daemon"}, false, "Enable daemon mode")
  28. flDebug = flag.Bool([]string{"D", "-debug"}, false, "Enable debug mode")
  29. flSocketGroup = flag.String([]string{"G", "-group"}, "docker", "Group to assign the unix socket specified by -H when running in daemon mode\nuse '' (the empty string) to disable setting of a group")
  30. flLogLevel = flag.String([]string{"l", "-log-level"}, "info", "Set the logging level")
  31. flEnableCors = flag.Bool([]string{"#api-enable-cors", "-api-enable-cors"}, false, "Enable CORS headers in the remote API")
  32. flTls = flag.Bool([]string{"-tls"}, false, "Use TLS; implied by --tlsverify flag")
  33. flHelp = flag.Bool([]string{"h", "-help"}, false, "Print usage")
  34. flTlsVerify = flag.Bool([]string{"-tlsverify"}, dockerTlsVerify, "Use TLS and verify the remote (daemon: verify client, client: verify daemon)")
  35. // these are initialized in init() below since their default values depend on dockerCertPath which isn't fully initialized until init() runs
  36. flTrustKey *string
  37. flCa *string
  38. flCert *string
  39. flKey *string
  40. flHosts []string
  41. )
  42. func init() {
  43. // placeholder for trust key flag
  44. trustKeyDefault := filepath.Join(dockerCertPath, defaultTrustKeyFile)
  45. flTrustKey = &trustKeyDefault
  46. flCa = flag.String([]string{"-tlscacert"}, filepath.Join(dockerCertPath, defaultCaFile), "Trust only remotes providing a certificate signed by the CA given here")
  47. flCert = flag.String([]string{"-tlscert"}, filepath.Join(dockerCertPath, defaultCertFile), "Path to TLS certificate file")
  48. flKey = flag.String([]string{"-tlskey"}, filepath.Join(dockerCertPath, defaultKeyFile), "Path to TLS key file")
  49. opts.HostListVar(&flHosts, []string{"H", "-host"}, "The socket(s) to bind to in daemon mode or connect to in client mode, specified using one or more tcp://host:port, unix:///path/to/socket, fd://* or fd://socketfd.")
  50. flag.Usage = func() {
  51. fmt.Fprint(os.Stdout, "Usage: docker [OPTIONS] COMMAND [arg...]\n\nA self-sufficient runtime for linux containers.\n\nOptions:\n")
  52. flag.CommandLine.SetOutput(os.Stdout)
  53. flag.PrintDefaults()
  54. help := "\nCommands:\n"
  55. for _, command := range [][]string{
  56. {"attach", "Attach to a running container"},
  57. {"build", "Build an image from a Dockerfile"},
  58. {"commit", "Create a new image from a container's changes"},
  59. {"cp", "Copy files/folders from a container's filesystem to the host path"},
  60. {"create", "Create a new container"},
  61. {"diff", "Inspect changes on a container's filesystem"},
  62. {"events", "Get real time events from the server"},
  63. {"exec", "Run a command in a running container"},
  64. {"export", "Stream the contents of a container as a tar archive"},
  65. {"history", "Show the history of an image"},
  66. {"images", "List images"},
  67. {"import", "Create a new filesystem image from the contents of a tarball"},
  68. {"info", "Display system-wide information"},
  69. {"inspect", "Return low-level information on a container"},
  70. {"kill", "Kill a running container"},
  71. {"load", "Load an image from a tar archive"},
  72. {"login", "Register or log in to a Docker registry server"},
  73. {"logout", "Log out from a Docker registry server"},
  74. {"logs", "Fetch the logs of a container"},
  75. {"port", "Lookup the public-facing port that is NAT-ed to PRIVATE_PORT"},
  76. {"pause", "Pause all processes within a container"},
  77. {"ps", "List containers"},
  78. {"pull", "Pull an image or a repository from a Docker registry server"},
  79. {"push", "Push an image or a repository to a Docker registry server"},
  80. {"rename", "Rename an existing container"},
  81. {"restart", "Restart a running container"},
  82. {"rm", "Remove one or more containers"},
  83. {"rmi", "Remove one or more images"},
  84. {"run", "Run a command in a new container"},
  85. {"save", "Save an image to a tar archive"},
  86. {"search", "Search for an image on the Docker Hub"},
  87. {"start", "Start a stopped container"},
  88. {"stop", "Stop a running container"},
  89. {"tag", "Tag an image into a repository"},
  90. {"top", "Lookup the running processes of a container"},
  91. {"unpause", "Unpause a paused container"},
  92. {"version", "Show the Docker version information"},
  93. {"wait", "Block until a container stops, then print its exit code"},
  94. } {
  95. help += fmt.Sprintf(" %-10.10s%s\n", command[0], command[1])
  96. }
  97. help += "\nRun 'docker COMMAND --help' for more information on a command."
  98. fmt.Fprintf(os.Stdout, "%s\n", help)
  99. }
  100. }