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

How to have a custom /etc/hosts in image? #3808

Closed
daledude opened this issue Jan 27, 2022 · 8 comments · Fixed by #3809
Closed

How to have a custom /etc/hosts in image? #3808

daledude opened this issue Jan 27, 2022 · 8 comments · Fixed by #3809

Comments

@daledude
Copy link

Not sure if this is a bug or intended. I find conflicting information regarding this so please excuse if I didn't file enough information.

I have code in Dockerfile to create a custom /etc/hosts file. But, saving and extracting the built image from "podman build" shows the /etc/hosts file is empty. I want to create my own /etc/hosts and use "podman run --no-hosts" but the build process seems to zero out my /etc/hosts file.

The description for --no-hosts is:
Do not create /etc/hosts within the container, instead use the version from the image

But, if my /etc/hosts is emptied at build time how can I use the version from the image?

@Luap99
Copy link
Member

Luap99 commented Feb 2, 2022

I think you have to run with podman build --network disabled to use the actual /etc/hosts file from the image and not a bind mount from the host.

@daledude
Copy link
Author

daledude commented Feb 3, 2022

Hi @Luap99

disabled isn't an option. I tried podman build --network none but it still zero's my image /etc/hosts file at build time.

@ttys3
Copy link

ttys3 commented Feb 3, 2022

  1. solution 1: use global
    edit /etc/containers/containers.conf and change #dns_searches = [] to
dns_servers = ["custom-dns1", "custom-dns2"]

replace custom-dns* with your own DNS

  1. solution 2: create the container with custom dns options.

see docs of podman create

@alitvak69
Copy link

alitvak69 commented Feb 3, 2022

@ttys3 This answer was unrelated to a actual question.
I found this link which states that changing hosts file can only happen in runtime for docker and since podman tries to be 100% docker compatible may be it is the case here.
PTL
https://stackoverflow.com/a/40721996

@rhatdan
Copy link
Member

rhatdan commented Feb 3, 2022

If you don't want the /etc/hosts file to be modified, you can use the --no-hosts option.

@Luap99
Copy link
Member

Luap99 commented Feb 3, 2022

This option does not exists for podman build

@rhatdan
Copy link
Member

rhatdan commented Feb 3, 2022

Ok, I guess we should add that.

@github-actions
Copy link

github-actions bot commented Mar 6, 2022

A friendly reminder that this issue had no activity for 30 days.

@rhatdan rhatdan transferred this issue from containers/podman Mar 7, 2022
rhatdan added a commit to rhatdan/buildah that referenced this issue Mar 7, 2022
Users want to turn off addition of /etc/hosts file while building
container images, this would allow them to customize the /etc/hosts
file within the image.

Fixes: containers#3808

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
rhatdan added a commit to rhatdan/buildah that referenced this issue Mar 8, 2022
Users want to turn off addition of /etc/hosts file while building
container images, this would allow them to customize the /etc/hosts
file within the image.

Fixes: containers#3808

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
rhatdan added a commit to rhatdan/buildah that referenced this issue Mar 8, 2022
Users want to turn off addition of /etc/hosts file while building
container images, this would allow them to customize the /etc/hosts
file within the image.

Fixes: containers#3808

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
rhatdan added a commit to rhatdan/buildah that referenced this issue Mar 8, 2022
Users want to turn off addition of /etc/hosts file while building
container images, this would allow them to customize the /etc/hosts
file within the image.

Fixes: containers#3808

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
rhatdan added a commit to rhatdan/buildah that referenced this issue Mar 10, 2022
Users want to turn off addition of /etc/hosts file while building
container images, this would allow them to customize the /etc/hosts
file within the image.

Fixes: containers#3808

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants