Set DOCKER_HOST
in the args to popen3()
instead of using --env
#2813
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We use
service-url
ininventory.yaml
to specify an alternate Docker server address. For example:This transport configuration has worked in the past with versions of Bolt 2. When we recently upgraded to Bolt 3, we found that the same configuration fails with a connection error. The error incorrectly refers to the default Docker socket,
/var/run/docker.sock
, instead of the Docker server specified by the inventory.Expected Behavior
The
command run
invocation should succeed:Steps to Reproduce
This procedure assumes that you have the Docker CLI client installed and are using an alternate socket or remote Docker host to access a container.
inventory.yaml
as follows:bolt command run
using the alternate Docker host:Success == output is
root
as expectedFailure == Bolt issues the connection error referring to the default Docker socket
Environment
Additional Context
The
execute()
method insidelib/bolt/transport/docker/connection.rb
uses--env
to pass theDOCKER_HOST
variable to thedocker exec
command.Although it's not clear in the Docker exec documentation, a direct test shows that
--env
sets variables inside the container. It does not change the process environment of thedocker exec
command itself. And that's whereDOCKER_HOST
is needed in this case.The suggested patch sets
DOCKER_HOST
by passingenv_hash
to the optionalenv
argument ofpopen3()
. This seems consistent with the other methods inconnection.rb
.With this change, the
bolt command run
invocation succeeds as expected with Bolt 3.7.1.