From 06bc4e07529a93abede35ea8fcc2906c5963f2a3 Mon Sep 17 00:00:00 2001 From: "Daniel, Dao Quang Minh" Date: Fri, 27 Jun 2014 02:52:36 -0400 Subject: [PATCH 1/3] Add logout command "docker logout [SERVER]" will remove the registry server' credentials from .dockercfg file. If a server is not specified, it will log user out of the default docker registry server Docker-DCO-1.1-Signed-off-by: Daniel, Dao Quang Minh (github: dqminh) --- api/client/commands.go | 31 +++++++++++++++++++++++ docs/man/docker-logout.1.md | 24 ++++++++++++++++++ docs/man/docker.1.md | 3 +++ docs/sources/reference/commandline/cli.md | 9 +++++++ 4 files changed, 67 insertions(+) create mode 100644 docs/man/docker-logout.1.md diff --git a/api/client/commands.go b/api/client/commands.go index c4e4cb9821..bc2a9ed75c 100644 --- a/api/client/commands.go +++ b/api/client/commands.go @@ -68,6 +68,7 @@ func (cli *DockerCli) CmdHelp(args ...string) error { {"kill", "Kill a running container"}, {"load", "Load an image from a tar archive"}, {"login", "Register or log in to the Docker registry server"}, + {"logout", "Logout of the Docker registry server"}, {"logs", "Fetch the logs of a container"}, {"port", "Lookup the public-facing port that is NAT-ed to PRIVATE_PORT"}, {"pause", "Pause all processes within a container"}, @@ -353,6 +354,36 @@ func (cli *DockerCli) CmdLogin(args ...string) error { return nil } +// logout of a registry service +func (cli *DockerCli) CmdLogout(args ...string) error { + cmd := cli.Subcmd("logout", "[SERVER]", "Logout of a docker registry server, if no server is specified \""+registry.IndexServerAddress()+"\" is the default.") + + if err := cmd.Parse(args); err != nil { + return nil + } + serverAddress := registry.IndexServerAddress() + if len(cmd.Args()) > 0 { + serverAddress = cmd.Arg(0) + } + + cli.LoadConfigFile() + if _, ok := cli.configFile.Configs[serverAddress]; !ok { + fmt.Fprintf(cli.out, "Not logged in to %s\n", serverAddress) + os.Exit(0) + } + + fmt.Fprintf(cli.out, "Remove login credentials for %s\n", serverAddress) + delete(cli.configFile.Configs, serverAddress) + + if err := registry.SaveConfig(cli.configFile); err != nil { + fmt.Fprintln(cli.out, "Failed to save docker config") + os.Exit(1) + } + + fmt.Fprintln(cli.out, "Saved docker config") + return nil +} + // 'docker wait': block until a container stops func (cli *DockerCli) CmdWait(args ...string) error { cmd := cli.Subcmd("wait", "CONTAINER [CONTAINER...]", "Block until a container stops, then print its exit code.") diff --git a/docs/man/docker-logout.1.md b/docs/man/docker-logout.1.md new file mode 100644 index 0000000000..1334fb3a55 --- /dev/null +++ b/docs/man/docker-logout.1.md @@ -0,0 +1,24 @@ +% DOCKER(1) Docker User Manuals +% William Henry +% APRIL 2014 +# NAME +docker-logout - Log the user out of a Docker registry server + +# SYNOPSIS +**docker logout** [SERVER] + +# DESCRIPTION +Log the user out of a docker registry server, , if no server is +specified "https://index.docker.io/v1/" is the default. If you want to +logout of a private registry you can specify this by adding the server name. + +# EXAMPLE + +## Logout of a local registry + + # docker logout localhost:8080 + +# HISTORY +April 2014, Originally compiled by William Henry (whenry at redhat dot com) +based on docker.io source material and internal work. + diff --git a/docs/man/docker.1.md b/docs/man/docker.1.md index 602c6e2ace..18e8978af6 100644 --- a/docs/man/docker.1.md +++ b/docs/man/docker.1.md @@ -124,6 +124,9 @@ inside it) **docker-login(1)** Register or Login to a Docker registry server +**docker-logout(1)** + Log the user out of a Docker registry server + **docker-logs(1)** Fetch the logs of a container diff --git a/docs/sources/reference/commandline/cli.md b/docs/sources/reference/commandline/cli.md index dac7c1610b..43acb17578 100644 --- a/docs/sources/reference/commandline/cli.md +++ b/docs/sources/reference/commandline/cli.md @@ -732,6 +732,15 @@ specify this by adding the server name. example: $ docker login localhost:8080 +## logout + + Usage: docker logout [SERVER] + + Log the user out of a docker registry server, if no server is specified "https://index.docker.io/v1/" is the default. + + example: + $ docker logout localhost:8080 + ## logs Usage: docker logs CONTAINER From 4b5b3b43212c0a1883c56321aedbffc605be31f9 Mon Sep 17 00:00:00 2001 From: "Daniel, Dao Quang Minh" Date: Sun, 29 Jun 2014 13:10:20 -0400 Subject: [PATCH 2/3] fix doc references Docker-DCO-1.1-Signed-off-by: Daniel, Dao Quang Minh (github: dqminh) --- api/client/commands.go | 8 ++++---- docs/man/docker-logout.1.md | 15 +++++++-------- docs/sources/reference/commandline/cli.md | 2 +- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/api/client/commands.go b/api/client/commands.go index bc2a9ed75c..446d9b7b0a 100644 --- a/api/client/commands.go +++ b/api/client/commands.go @@ -67,8 +67,8 @@ func (cli *DockerCli) CmdHelp(args ...string) error { {"inspect", "Return low-level information on a container"}, {"kill", "Kill a running container"}, {"load", "Load an image from a tar archive"}, - {"login", "Register or log in to the Docker registry server"}, - {"logout", "Logout of the Docker registry server"}, + {"login", "Register or log in to a Docker registry server"}, + {"logout", "Log out from a Docker registry server"}, {"logs", "Fetch the logs of a container"}, {"port", "Lookup the public-facing port that is NAT-ed to PRIVATE_PORT"}, {"pause", "Pause all processes within a container"}, @@ -354,9 +354,9 @@ func (cli *DockerCli) CmdLogin(args ...string) error { return nil } -// logout of a registry service +// log out from a Docker registry func (cli *DockerCli) CmdLogout(args ...string) error { - cmd := cli.Subcmd("logout", "[SERVER]", "Logout of a docker registry server, if no server is specified \""+registry.IndexServerAddress()+"\" is the default.") + cmd := cli.Subcmd("logout", "[SERVER]", "Log out from a Docker registry, if no server is specified \""+registry.IndexServerAddress()+"\" is the default.") if err := cmd.Parse(args); err != nil { return nil diff --git a/docs/man/docker-logout.1.md b/docs/man/docker-logout.1.md index 1334fb3a55..0196f0ed7d 100644 --- a/docs/man/docker-logout.1.md +++ b/docs/man/docker-logout.1.md @@ -1,24 +1,23 @@ % DOCKER(1) Docker User Manuals -% William Henry -% APRIL 2014 +% Daniel, Dao Quang Minh +% JUNE 2014 # NAME -docker-logout - Log the user out of a Docker registry server +docker-logout - Log out from a Docker registry # SYNOPSIS **docker logout** [SERVER] # DESCRIPTION -Log the user out of a docker registry server, , if no server is +Log the user out from a Docker registry, if no server is specified "https://index.docker.io/v1/" is the default. If you want to -logout of a private registry you can specify this by adding the server name. +log out from a private registry you can specify this by adding the server name. # EXAMPLE -## Logout of a local registry +## Log out from a local registry # docker logout localhost:8080 # HISTORY -April 2014, Originally compiled by William Henry (whenry at redhat dot com) -based on docker.io source material and internal work. +June 2014, Originally compiled by Daniel, Dao Quang Minh (daniel at nitrous dot io) diff --git a/docs/sources/reference/commandline/cli.md b/docs/sources/reference/commandline/cli.md index 43acb17578..56acc33310 100644 --- a/docs/sources/reference/commandline/cli.md +++ b/docs/sources/reference/commandline/cli.md @@ -736,7 +736,7 @@ specify this by adding the server name. Usage: docker logout [SERVER] - Log the user out of a docker registry server, if no server is specified "https://index.docker.io/v1/" is the default. + Log out from a Docker registry, if no server is specified "https://index.docker.io/v1/" is the default. example: $ docker logout localhost:8080 From 56a39ca5d3010785e3b4be849c6b13c69a23721d Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Fri, 18 Jul 2014 17:52:24 +0000 Subject: [PATCH 3/3] update style Docker-DCO-1.1-Signed-off-by: Victor Vieux (github: vieux) --- api/client/commands.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/api/client/commands.go b/api/client/commands.go index 446d9b7b0a..65c06ba15c 100644 --- a/api/client/commands.go +++ b/api/client/commands.go @@ -369,18 +369,14 @@ func (cli *DockerCli) CmdLogout(args ...string) error { cli.LoadConfigFile() if _, ok := cli.configFile.Configs[serverAddress]; !ok { fmt.Fprintf(cli.out, "Not logged in to %s\n", serverAddress) - os.Exit(0) + } else { + fmt.Fprintf(cli.out, "Remove login credentials for %s\n", serverAddress) + delete(cli.configFile.Configs, serverAddress) + + if err := registry.SaveConfig(cli.configFile); err != nil { + return fmt.Errorf("Failed to save docker config: %v", err) + } } - - fmt.Fprintf(cli.out, "Remove login credentials for %s\n", serverAddress) - delete(cli.configFile.Configs, serverAddress) - - if err := registry.SaveConfig(cli.configFile); err != nil { - fmt.Fprintln(cli.out, "Failed to save docker config") - os.Exit(1) - } - - fmt.Fprintln(cli.out, "Saved docker config") return nil }