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