Skip to content
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

[feature requests] extra_hosts support #69

Closed
Oloremo opened this issue Feb 7, 2021 · 2 comments · Fixed by #71
Closed

[feature requests] extra_hosts support #69

Oloremo opened this issue Feb 7, 2021 · 2 comments · Fixed by #71
Assignees
Labels
enhancement New feature or request

Comments

@Oloremo
Copy link

Oloremo commented Feb 7, 2021

Hi,

It'd be nice to see the same feature as in Docker driver: https://www.nomadproject.io/docs/drivers/docker#extra_hosts

@shishir-a412ed shishir-a412ed self-assigned this Feb 8, 2021
@shishir-a412ed shishir-a412ed added the enhancement New feature or request label Feb 8, 2021
@shishir-a412ed
Copy link
Contributor

@Oloremo I looked into this, but this is not trivial! Currently, there is no support for extra_hosts (--add-host in docker run) in containerd so I cannot just directly integrate with an existing containerd API. It might be by design (I have to check with the maintainers in their community slack) since they wanted to keep containerd lightweight and wanted to keep networking out of the scope of containerd.

I just started looking into the moby/moby codebase and see if I can find a reference implementation on how docker implements this, and try to implement it directly in containerd-driver.

@shishir-a412ed
Copy link
Contributor

shishir-a412ed commented Feb 24, 2021

@Oloremo I have opened #71 to add support for extra_hosts
Once merged, I will release a new version (0.7) for containerd-driver which should have this feature.

One small thing I would like to call out in this PR, which is a bit different than the docker behavior of extra_hosts.

In docker when you are trying to add an extra_host along with host network network_mode=host.
You are specifically requesting for host network and ideally should get /etc/hosts of the host system, and extra_hosts should be added to that.

Docker however adds extra_hosts to the local version of /etc/hosts eventhough network_mode=host was selected.
I am not sure if this is by design or a bug. However, I have addressed that in containerd-driver and you'll get what you asked for.

SM-smahajan628:~ smahajan$ cat /etc/hosts (Host)
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1	localhost
255.255.255.255	broadcasthost
::1             localhost
# Added by Docker Desktop
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section

SM-smahajan628:~ smahajan$ docker run -it --rm --net=host --add-host "postgres:127.0.1.2" ubuntu:16.04 cat /etc/hosts (CONTAINER)
127.0.0.1	localhost
::1	localhost ip6-localhost ip6-loopback
fe00::0	ip6-localnet
ff00::0	ip6-mcastprefix
ff02::1	ip6-allnodes
ff02::2	ip6-allrouters
127.0.1.2	postgres

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants