-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
Allow customization of /etc/hosts, /etc/resolv.conf, etc. in containers #2267
Comments
I think we need a name for the list of files in graph.go:203 so that we can refer to the list as a whole. I'm going to call them the DockerInitLayer Files until someone tells me different. Its descriptive and greppable in the code. I agree that a simple flag on a commit is an ok way to override the default behavior (i.e. if the default behavior is to ignore the DockerInitLayer files when committing, then the flag would indicate that the committer wants them preserved, or if the default is to always include them, the the flag would indicate they should be excluded from the image). But what happens on I like how your proposed Is there a way to unify this with the way we handle data volumes and bind mounts? That is "here are some special files that we want to be (readable | read-writable) within the container and we (do | do not) want to be included in the container's changes when committing to an image or diffing. The data for the file actually lives ( on this mount point for the host | in another container | etc). Initialize the file with ( an empty file | this file | etc)." It seems like a unified approach could be easier to learn and make defaults easier to document and override. |
@unclejack we can set the dns server names as suggested by you. but it will be better to edit the resolv.conf file because we need to add search option in resolv.conf since we dont use fully qualified domains names for internally used links. |
Second that, we also need to be able to configure the resolv.conf search option. |
Now that 0.7 is out, maybe this can get some priority? |
I also really need to set search option in resolv.conf ; now I am working with internal services that return urls that rely on the correct search settings. |
I would also really like to see this get fixed. |
+1 |
2 similar comments
+1 |
+1 |
This issue is very important to me right now as well. |
Ok I think we're in good shape to fix this now. Every container in 0.7 has a writeable init layer which can be changed before starting, for customizations like this. On Tue, Dec 10, 2013 at 3:16 PM, Jeff Baier notifications@github.com
|
Tentatively scheduling for 0.8 |
+1 |
I would want to configure not only at creation time but at any time of the container living, and i am voting for it to just be a normal writable file in the filesystem as it would already have been for years and not mounted r-o on a special layer :) (related to #2276) |
+1 |
+1 , agree with kiorky need be able to modify hosts file at any time not just during creation. Not having that is a show stopper for me. |
I would just explicitly note that i want to be able to edit any file, not only /etc/hosts. |
+1 |
1 similar comment
+1 |
The only bottleneck for this is development time. If somebody wants to contribute it, we can help you. Otherwise, it will be done eventually :) On Tue, Dec 24, 2013 at 8:51 AM, Yuvaraj notifications@github.com wrote:
|
hi, I am trying to put several services into different docker containers. And I want them to have property hostname before the service start. But in the dockerfile, I can't write the hostname info into /etc/hosts, can we have this function? Thanks a lot. |
+1 |
@netroby define "real world" prod environment That said, you can add resolvers using the If you are having some specific problem I'd be happy to discuss a solution on IRC. |
Ok, i got another problem, how to modify the flags with exists container? I creat the container before, and now i want change some config, such as port bind and dns options. |
@netroby This is not the place to discuss this. |
Just started on docker, what an amazing thing to have. But I hit this problem even before I have my first non-playaround image up and running. --dns works fine on docker run But I need it to be present on docker build, so I can reach internal repositories and whatnot to build my image. Bang, I'm dead because the image seems to be hard coded to using dns 8.8.8.8 during docker build. How to work around that, I wonder... |
I have been using |
This is done actually, i am using docker Docker version 1.4.1 you can add entry into your docker with option --add-host="" sample ~#$ sudo docker run -i -t -p 80:80 --add-host='logserver:127.0.0.1' ubuntu/14.04 /bin/bash sample with multiple entry ~#$ sudo docker run -i -t -p 80:80 --add-host='javacronserver:127.0.0.1' --add-host='dbserver:127.0.0.1' --add-host='logserver:127.0.0.1' ubuntu/14.04 /bin/bash |
Thanks @addhewarman. The |
Thanks @addhewarman. The --add-hosts flag worked like a charm. |
… container. See Docker bug 2267: moby/moby#2267
@addhewarman |
to be honest what you face is exactly like mine but in my case i am not using container so how i update my resolv.conf is simply using ansible to update my /etc/resolv.conf. and what we're doing is simply wrong and it's not the best way how to do it, if you are always change information in /etc/resolv.conf then you will face what i face when i am creating my 'disaster recovery' implementing chaos monkey state of immutable infra. something in-between your infra will break and stop working. so here's i recommend you 👍
just note to everyone that using docker, docker is container and you should remember the docker philosophy ( one concern per container ) this will make your life easier using it. Note: For containers which were created prior to the implementation of the /etc/resolv.conf update feature in Docker 1.5.0: those containers will not receive updates when the host resolv.conf file changes. Only containers created with Docker 1.5.0 and above will utilize this auto-update feature. |
… container. See Docker bug 2267: moby/moby#2267
My solution: |
It's customizable for a long time... |
@cpuguy83 : can you point me to the documentation that describes how? |
@aries1980 you can just write to it like normal or use "--add-host" (or both) |
fix error when make lint
(Sorry if this is a duplicate; but I remember that I had a very extensive conversation with @creack a while ago about this topic, and I thought that we had written our conclusions to a GitHub issue; but I cannot find said issue; so it looks like we hadn't, after all.)
Some people need to customize /etc/hosts, /etc/resolv.conf, or even /.dockerinit.
(See for instance #1951 and #2068, as well as this message on docker-user).
#1959 provides a naive implementation, making the bind-mounted files read-write. It works, but changes are lost since those files are regenerated.
The idea discussed with @creack was the following (as far as I can remember):
docker commit
ordocker diff
, check if the files have been changed (i.e. if they are different from what they were when the container was started), and include them only if they were changed (which means that dynamically generated files won't be included if they haven't been changed).Those files are already listed in graph.go:203, and this comment in image.go:407 might indicate that the device mapper branch already implements part of what's needed.
The main outstanding issue is to decide whether to require a special flag to commit those special files, to avoid unwanted modifications (e.g. "Something changed the hostname or DNS configuration in my container, and all images derived from that container are broken!").
Requiring a special flag for
docker commit
makes sense (-f
, likeforce
?); however, fordocker build
, it's a bit more complex. Maybe theDockerfile
could include a special directive saying explicitly "this Dockerfile generates an image with a modifiedresolv.conf
", e.g.CUSTOM /etc/resolv.conf /etc/hosts
./cc @creack @metalivedev @shykes for feedback.
The text was updated successfully, but these errors were encountered: