-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docker: generate /etc/hosts file for bridge network mode #10766
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a quick read and the approach seems good. A couple of minor comments you can consider, and plan to do another round of review later today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM; I like the thought of doing the same to exec/java
in #10768 in the next feature release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Great - thanks!
When `network.mode = "bridge"`, we create a pause container in Docker with no networking so that we have a process to hold the network namespace we create in Nomad. The default `/etc/hosts` file of that pause container is then used for all the Docker tasks that share that network namespace. Some applications rely on this file being populated. This changeset generates a `/etc/hosts` file and bind-mounts it to the container when Nomad owns the network, so that the container's hostname has an IP in the file as expected. The hosts file will include the entries added by the Docker driver's `extra_hosts` field. In this changeset, only the Docker task driver will take advantage of this option, as the `exec`/`java` drivers currently copy the host's `/etc/hosts` file and this can't be changed without breaking backwards compatibility. But the fields are available in the task driver protobuf for community task drivers to use if they'd like.
I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions. |
Fixes #8900 and #7746. This is heavily based on @nickethier's earlier work on
/etc/resolv.conf
When
network.mode = "bridge"
, we create a pause container in Docker with nonetworking so that we have a process to hold the network namespace we create
in Nomad. The default
/etc/hosts
file of that pause container is then usedfor all the Docker tasks that share that network namespace. Some applications
rely on this file being populated.
This changeset generates a
/etc/hosts
file and bind-mounts it to thecontainer when Nomad owns the network, so that the container's hostname has an
IP in the file as expected. The hosts file will include the entries added by
the Docker driver's
extra_hosts
field.In this changeset, only the Docker task driver will take advantage of this
option, as the
exec
/java
drivers currently copy the host's/etc/hosts
file and this can't be changed without breaking backwards compatibility. But
the fields are available in the task driver protobuf for community task
drivers to use if they'd like.
With this changeset, and the following job:
jobspec
Results:
I've tested this out in non-bridge networking modes and we're correctly leaving everything untouched as expected.