Skip to content

Conversation

@thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Dec 13, 2018

relates to: #93
fixes docker/for-linux#369

Proxies configured in config.json were only taking effect when using docker run, but were being ignored when using docker create.

Before this change:

echo '{"proxies":{"default":{"httpProxy":"httpProxy","httpsProxy":"httpsProxy","noProxy":"noProxy","ftpProxy":"ftpProxy"}}}' > config.json
docker inspect --format '{{.Config.Env}}' $(docker --config=./ create busybox)
[PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin]

With this change applied:

echo '{"proxies":{"default":{"httpProxy":"httpProxy","httpsProxy":"httpsProxy","noProxy":"noProxy","ftpProxy":"ftpProxy"}}}' > config.json
docker inspect --format '{{.Config.Env}}' $(docker --config=./ create busybox)
[NO_PROXY=noProxy no_proxy=noProxy FTP_PROXY=ftpProxy ftp_proxy=ftpProxy HTTP_PROXY=httpProxy http_proxy=httpProxy HTTPS_PROXY=httpsProxy https_proxy=httpsProxy PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin]

Reported-by: Silvano Cirujano Cuesta [email protected]
Signed-off-by: Sebastiaan van Stijn [email protected]

- Description for the changelog

- Fix proxy-configuration being ignored on docker create [docker/cli#1573](https://github.com/docker/cli/pull/1573)

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah
Copy link
Member Author

ping @dave-tucker PTAL 😅

@codecov-io
Copy link

codecov-io commented Dec 13, 2018

Codecov Report

Merging #1573 into master will increase coverage by <.01%.
The diff coverage is 70%.

@@            Coverage Diff             @@
##           master    #1573      +/-   ##
==========================================
+ Coverage   55.16%   55.16%   +<.01%     
==========================================
  Files         301      301              
  Lines       20384    20392       +8     
==========================================
+ Hits        11244    11249       +5     
- Misses       8335     8336       +1     
- Partials      805      807       +2

Proxies configured in config.json were only taking effect
when using `docker run`, but were being ignored when
using `docker create`.

Before this change:

    echo '{"proxies":{"default":{"httpProxy":"httpProxy","httpsProxy":"httpsProxy","noProxy":"noProxy","ftpProxy":"ftpProxy"}}}' > config.json
    docker inspect --format '{{.Config.Env}}' $(docker --config=./ create busybox)
    [PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin]

With this change applied:

    echo '{"proxies":{"default":{"httpProxy":"httpProxy","httpsProxy":"httpsProxy","noProxy":"noProxy","ftpProxy":"ftpProxy"}}}' > config.json
    docker inspect --format '{{.Config.Env}}' $(docker --config=./ create busybox)
    [NO_PROXY=noProxy no_proxy=noProxy FTP_PROXY=ftpProxy ftp_proxy=ftpProxy HTTP_PROXY=httpProxy http_proxy=httpProxy HTTPS_PROXY=httpsProxy https_proxy=httpsProxy PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin]

Reported-by: Silvano Cirujano Cuesta <[email protected]>
Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah thaJeztah force-pushed the fix_proxy_on_create branch from cc6a92c to 91bc4dd Compare January 19, 2019 11:33
@thaJeztah
Copy link
Member Author

ping @silvin-lubecki @vdemeester PTAL

Copy link
Contributor

@dave-tucker dave-tucker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thaJeztah
Copy link
Member Author

ping @silvin-lubecki @vdemeester PTAL 🙏

Copy link
Collaborator

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🐯

func runCreate(dockerCli command.Cli, flags *pflag.FlagSet, opts *createOptions, copts *containerOptions) error {
func runCreate(dockerCli command.Cli, flags *pflag.FlagSet, options *createOptions, copts *containerOptions) error {
proxyConfig := dockerCli.ConfigFile().ParseProxyConfig(dockerCli.Client().DaemonHost(), copts.env.GetAll())
newEnv := []string{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: var newEnv []string

Copy link
Contributor

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this proxy configuration is now handled by runCreate, shouldn't we remove the exact same code from runRun ? Or if not, at least factorize the common code between the two commands?

@thaJeztah
Copy link
Member Author

Or if not, at least factorize the common code between the two commands?

Ideally, we would be able to share more code; the reason I did not do this (and instead went for some small amount of duplication), is that I wanted to keep the code changes minimal (in case we wanted to backport), and didn't want to put the cli-configuration handling too deep into the stack;

  • runRun (cli specific code) converts the CLI options into a more generic containeroptions
    • calls runContainer (apply "run" specific options)
    • calls createContainer with the given options and container-configuration
  • runCreate (cli specific code) converts the CLI options into a more generic containeroptions
    • calls createContainer with the given options and container-configuration

In the above, possibly runRun and runContainer could be (partially) combined, but perhaps best left to a bigger refactor (we should more clearly define the "hand-off" point between CLI and "API/client" code).

@silvin-lubecki
Copy link
Contributor

That makes sense, thank you @thaJeztah 👍

Copy link
Contributor

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@silvin-lubecki silvin-lubecki merged commit b258f45 into docker:master Jan 29, 2019
@GordonTheTurtle GordonTheTurtle added this to the 19.03.0 milestone Jan 29, 2019
@thaJeztah thaJeztah deleted the fix_proxy_on_create branch April 23, 2025 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

User proxy configuration doesn't work with docker create + start

6 participants