How to change resolv.conf for existing docker containers - Stack Overflow (https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png?v=c78bd457575a) (Stack Overflow) (https://stackoverflow.com/opensearch.xml) (https://stackoverflow.com/questions/33947873/how-to-change-resolv-conf-for-existing-docker-containers) (Feed for question 'How to change resolv.conf for existing docker containers') (https://stackoverflow.com/feeds/question/33947873) (site logo) By clicking “Sign up”, you agree to our (https://stackoverflow.com/legal/terms-of-service/public) terms of service and acknowledge you have read our (https://stackoverflow.com/legal/privacy-policy) privacy policy . Sign up with Google Sign up with GitHub OR Email Password (8+ characters (at least 1 letter & 1 number)) Sign up Already have an account? (https://stackoverflow.com/users/login) Log in Skip to main content (https://stackoverflow.com/) Stack Overflow (https://stackoverflow.co/) About Products (https://stackoverflow.co/teams/) For Teams (Search…) (Click to show search) (https://stackoverflow.com/users/login?ssrc=head&returnurl=https%3a%2f%2fstackoverflow.com%2fquestions%2f33947873%2fhow-to-change-resolv-conf-for-existing-docker-containers) Log in (https://stackoverflow.com/users/signup?ssrc=head&returnurl=https%3a%2f%2fstackoverflow.com%2fquestions%2f33947873%2fhow-to-change-resolv-conf-for-existing-docker-containers) Sign up Let's set up your homepage Select a few topics you're interested in: python javascript c# reactjs java android html flutter c++ node.js typescript css r php angular next.js spring-boot machine-learning sql excel ios azure docker Or search from our full list: (Search) Next You’ll be prompted to create an account to view your personalized homepage. (https://stackoverflow.com/) Home (https://stackoverflow.com/questions) Questions (https://stackoverflow.ai/) AI Assist Labs (https://stackoverflow.com/tags) Tags (https://stackoverflow.com/beta/challenges) Challenges (https://chat.stackoverflow.com/rooms/259507/stack-overflow-lobby) Chat (https://stackoverflow.blog/contributed?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=so-blog&utm_content=experiment-articles) Articles (https://stackoverflow.com/users) Users (https://stackoverflow.com/jobs?source=so-left-nav) Jobs (https://stackoverflow.com/jobs/companies?so_medium=stackoverflow&so_source=SiteNav) Companies Collectives Communities for your favorite technologies. (https://stackoverflow.com/collectives-all) Explore all Collectives Teams Ask questions, find answers and collaborate at work with Stack Overflow for Teams. (https://stackoverflowteams.com/teams/create/free/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=side-bar&utm_content=explore-teams) Try Teams for free (https://stackoverflow.co/teams/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=side-bar&utm_content=explore-teams) Explore Teams (Illustration of upvote icon after it is clicked) Hang on, you can't upvote just yet. You'll need to complete a few actions and gain 15 reputation points before being able to upvote. Upvoting indicates when questions and answers are useful. (https://stackoverflow.com/help/whats-reputation) What's reputation and how do I get it? Instead, you can save this post to reference later. Save this post for later Not now (Illustration of upvote icon after it is clicked) Thanks for your vote! You now have 5 free votes weekly. Free votescount toward the total vote score does not give reputation to the author Continue to help good content that is interesting, well-researched, and useful, rise to the top! To gain full voting privileges, (https://stackoverflow.com/help/whats-reputation) earn reputation . Got it! Go to help center to learn more (https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png?v=c78bd457575a) (https://stackoverflow.com/questions/33947873/how-to-change-resolv-conf-for-existing-docker-containers) How to change resolv.conf for existing docker containers (https://stackoverflow.com/questions/ask) Ask Question (2015-11-26 22:31:41Z) Asked 9 years, 10 months ago Modified (https://stackoverflow.com/questions/33947873/how-to-change-resolv-conf-for-existing-docker-containers?lastactivity) (2020-11-19 00:51:35Z) 4 years, 10 months ago (Viewed 1,971 times) Viewed 2k times This question shows research effort; it is useful and clear 4 (This question does not show any research effort; it is unclear or not useful) Save this question. (https://stackoverflow.com/posts/33947873/timeline) Show activity on this post. I recently upgraded docker version on my Ubuntu to latest 1.9 version. During the upgrade docker network bridge gateway has changed from 172.17.42.1 to 172.17.0.1 . I had some existing containers where the resolv.conf still points to 172.17.42.1 so whenever I restart my container the resolv.conf is resetting to 172.17.42.1 . I tried to modify the /var/lib/docker/containers//resolv.conf but it has no effect. Currently whenever I restart the container I connect to container and change /etc/resolv.conf file manually. This changes to this file are lost during container restart. I don't want to kill my container and re-create them again. Is there any way to make my resolv.conf permanent for existing containers? Thanks in advance -Kesav (https://stackoverflow.com/questions/tagged/docker) (show questions tagged 'docker') docker (https://stackoverflow.com/q/33947873) (Short permalink to this question) Share (https://stackoverflow.com/posts/33947873/edit) Improve this question Follow Follow this question to receive notifications asked (2015-11-26 22:31:41Z) Nov 26, 2015 at 22:31 (https://stackoverflow.com/users/184663/kesavkolla) (kesavkolla's user avatar) (https://stackoverflow.com/users/184663/kesavkolla) kesavkolla kesavkolla (reputation score) 459 (5 silver badges) 5 5 silver badges (14 bronze badges) 14 14 bronze badges (Use comments to ask for more information or suggest improvements. Avoid answering questions in comments.) Add a comment | (Expand to show all comments on this post) 1 Answer 1 Sorted by: (https://stackoverflow.com/questions/33947873/how-to-change-resolv-conf-for-existing-docker-containers?answertab=scoredesc#tab-top) Reset to default (scoredesc) Highest score (default) (trending) Trending (recent votes count more) (modifieddesc) Date modified (newest first) (createdasc) Date created (oldest first) This answer is useful 0 (This answer is not useful) Save this answer. (Loading when this answer was accepted…) (https://stackoverflow.com/posts/64903732/timeline) Show activity on this post. Im building portable system that change host network a lot, the solution i found was create your container as a host and bind a volume from host resolv.conf to the container resolv.conf mainly due because if the network changes when the container is already up it will not update here is an example of the docker-compose service declaration gpioctl: container_name: gpioctl image: registry.gitlab.com/absadevelopers/bluetoothgateway/bluetoothgateway_gpioctl network_mode: host volumes: - /var/log/knesys:/var/log/knesys - /etc/resolv.conf:/etc/resolv.conf:ro restart: unless-stopped depends_on: - nodesetup (https://stackoverflow.com/a/64903732) (Short permalink to this answer) Share (https://stackoverflow.com/posts/64903732/edit) Improve this answer Follow Follow this answer to receive notifications answered (2020-11-19 00:51:35Z) Nov 19, 2020 at 0:51 (https://stackoverflow.com/users/12305425/alberto-martinez) (Alberto Martinez's user avatar) (https://stackoverflow.com/users/12305425/alberto-martinez) Alberto Martinez Alberto Martinez (reputation score) 17 (2 bronze badges) 2 2 bronze badges Sign up to request clarification or add additional context in comments. Comments Add a comment Your Answer Draft saved Draft discarded Sign up or (https://stackoverflow.com/users/login?ssrc=question_page&returnurl=https%3a%2f%2fstackoverflow.com%2fquestions%2f33947873%2fhow-to-change-resolv-conf-for-existing-docker-containers%23new-answer) log in Sign up using Google Sign up using Email and Password Submit Post as a guest Name Email Required, but never shown Post as a guest Name () () Email Required, but never shown () () Post Your Answer Discard By clicking “Post Your Answer”, you agree to our (https://stackoverflow.com/legal/terms-of-service/public) terms of service and acknowledge you have read our (https://stackoverflow.com/legal/privacy-policy) privacy policy . Start asking to get answers Find the answer to your question by asking. (https://stackoverflow.com/questions/ask) Ask question Explore related questions (https://stackoverflow.com/questions/tagged/docker) (show questions tagged 'docker') docker See similar questions with these tags. The Overflow Blog (https://stackoverflow.blog/2025/10/07/context-is-king-for-secure-ai-generated-code/?cb=1) Context is king for secure, AI-generated code Featured on Meta (Meta Stack Exchange) (https://meta.stackexchange.com/questions/412987/please-welcome-v2blast-back-to-the-community-team?cb=1) Please welcome V2Blast back to the Community Team! (Meta Stack Exchange) (https://meta.stackexchange.com/questions/412992/a-first-look-stack-overflow-redesign?cb=1) A First Look: Stack Overflow Redesign (Meta Stack Overflow) (https://meta.stackoverflow.com/questions/421831/policy-generative-ai-e-g-chatgpt-is-banned?cb=1) Policy: Generative AI (e.g., ChatGPT) is banned (Meta Stack Overflow) (https://meta.stackoverflow.com/questions/435121/exploring-new-types-of-questions-on-stack-overflow?cb=1) Exploring new types of questions on Stack Overflow Related (https://stackoverflow.com/questions/20771269/change-docker-containers-ip-address?rq=3) (Question score (upvotes - downvotes)) 11 (https://stackoverflow.com/questions/20771269/change-docker-containers-ip-address?rq=3) change docker containers IP address (https://stackoverflow.com/questions/27655848/how-to-specify-docker-images-dns?rq=3) (Question score (upvotes - downvotes)) 0 (https://stackoverflow.com/questions/27655848/how-to-specify-docker-images-dns?rq=3) How to specify docker image's DNS? (https://stackoverflow.com/questions/34296230/how-to-change-default-docker-machines-dns-settings?rq=3) (Question score (upvotes - downvotes)) 29 (https://stackoverflow.com/questions/34296230/how-to-change-default-docker-machines-dns-settings?rq=3) How to change "default" docker-machine's dns settings (https://stackoverflow.com/questions/36358331/docker-setting-up-dns-for-containers?rq=3) (Question score (upvotes - downvotes)) 4 (https://stackoverflow.com/questions/36358331/docker-setting-up-dns-for-containers?rq=3) Docker: Setting up dns for containers (https://stackoverflow.com/questions/36905581/docker-how-to-start-container-with-defined-nameservers-in-etc-resolv-conf?rq=3) (Question score (upvotes - downvotes)) 13 (https://stackoverflow.com/questions/36905581/docker-how-to-start-container-with-defined-nameservers-in-etc-resolv-conf?rq=3) Docker how to start container with defined nameservers in /etc/resolv.conf (https://stackoverflow.com/questions/41032744/unable-to-edit-etc-resolv-conf-in-docker-container?rq=3) (Question score (upvotes - downvotes)) 18 (https://stackoverflow.com/questions/41032744/unable-to-edit-etc-resolv-conf-in-docker-container?rq=3) unable to edit /etc/resolv.conf in docker container (https://stackoverflow.com/questions/41243665/docker-compose-does-not-update-resolv-conf?rq=3) (Question score (upvotes - downvotes)) 14 (https://stackoverflow.com/questions/41243665/docker-compose-does-not-update-resolv-conf?rq=3) docker-compose does not update resolv.conf (https://stackoverflow.com/questions/42265346/dns-resolution-with-the-container?rq=3) (Question score (upvotes - downvotes)) 2 (https://stackoverflow.com/questions/42265346/dns-resolution-with-the-container?rq=3) DNS resolution with the container (https://stackoverflow.com/questions/43907206/docker-container-dns-resolution?rq=3) (Question score (upvotes - downvotes)) 0 (https://stackoverflow.com/questions/43907206/docker-container-dns-resolution?rq=3) Docker Container DNS resolution (https://stackoverflow.com/questions/47041507/how-to-override-embedded-dns-server-for-docker-in-etc-resolv-conf-from-a-docker?rq=3) (Question score (upvotes - downvotes)) 4 (https://stackoverflow.com/questions/47041507/how-to-override-embedded-dns-server-for-docker-in-etc-resolv-conf-from-a-docker?rq=3) How to override embedded DNS server for Docker in /etc/resolv.conf from a docker-compose file (https://stackexchange.com/questions?tab=hot) Hot Network Questions (Server Fault) (https://serverfault.com/questions/1193268/how-to-restrict-access-to-an-ec2-instance-on-aws-to-only-users-on-a-certain-vpn) How to restrict access to an EC2 instance on AWS to only users on a certain VPN? (Super User) (https://superuser.com/questions/1926203/how-to-make-a-specific-program-prefer-wi-fi-over-ethernet-in-windows) How to make a specific program prefer Wi-Fi over Ethernet in Windows? (Unix & Linux Stack Exchange) (https://unix.stackexchange.com/questions/800297/allow-unicode-characters-in-zsh-shell-variable-names-on-macos) Allow unicode characters in zsh shell variable names on MacOS (Personal Finance & Money Stack Exchange) (https://money.stackexchange.com/questions/166783/when-applying-for-a-credit-card-in-the-us-is-it-normal-to-be-asked-for-verifyin) When applying for a credit card in the US, is it normal to be asked for verifying documents? Should I redact nonessential information? (English Language Learners Stack Exchange) (https://ell.stackexchange.com/questions/368701/is-know-how-color-a-common-expression-or-the-authors-stylistic-device) Is "know-how color" a common expression or the author's stylistic device? (Philosophy Stack Exchange) (https://philosophy.stackexchange.com/questions/131031/does-maya-in-advaita-vedanta-imply-impossibility-of-knowledge) Does maya in Advaita Vedanta imply impossibility of knowledge? (Biblical Hermeneutics Stack Exchange) (https://hermeneutics.stackexchange.com/questions/108690/are-the-our-father-mentioned-in-matthew-69-and-isaiah-6316-one-and-the-same) Are the "our Father" mentioned in Matthew 6:9 and Isaiah 63:16 one and the same? (Super User) (https://superuser.com/questions/1926322/how-to-use-a-lets-encrypt-certificate-on-multiple-servers-in-different-vlans) How to use a Let's Encrypt certificate on multiple servers in different VLANs? (Science Fiction & Fantasy Stack Exchange) (https://scifi.stackexchange.com/questions/299518/when-was-dr-who-shown-on-dr-who) When was Dr Who shown on Dr Who? (Philosophy Stack Exchange) (https://philosophy.stackexchange.com/questions/131040/is-it-possible-to-create-a-language-with-no-paradoxical-statements) Is it possible to create a language with no paradoxical statements? (Philosophy Stack Exchange) (https://philosophy.stackexchange.com/questions/131001/an-interesting-argument-against-the-a-theory-of-time) An interesting argument against the A-theory of time (German Language Stack Exchange) (https://german.stackexchange.com/questions/80786/an-etwas-d-festhalten-vs-sich-an-etwas-d-festhalten) an etwas (D) festhalten vs. sich an etwas (D) festhalten more hot questions (https://stackoverflow.com/feeds/question/33947873) (Feed of this question and its answers) Question feed Subscribe to RSS Question feed To subscribe to this RSS feed, copy and paste this URL into your RSS reader. (https://stackoverflow.com/feeds/question/33947873) () Why are you flagging this comment? (45) Probable spam. This comment promotes a product, service or website while (https://stackoverflow.com/help/promotion) failing to disclose the author's affiliation . (20) Unfriendly or contains harassment/bigotry/abuse. This comment is unkind, insulting or attacks another person or group. Learn more in our (https://stackoverflow.com/conduct/abusive-behavior) Code of Conduct . (39) Not needed. This comment is not relevant to the post. (19) Something else. A problem not listed above. Try to be as specific as possible. Flag comment Cancel You have 0 flags left today (GPP Locator) (https://stackoverflow.com/) (https://stackoverflow.com/) Stack Overflow (https://stackoverflow.com/questions) Questions (https://stackoverflow.com/help) Help (https://chat.stackoverflow.com/?tab=explore) Chat (https://stackoverflow.co/) Products (https://stackoverflow.co/teams/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=footer&utm_content=teams) Teams (https://stackoverflow.co/advertising/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=footer&utm_content=advertising) Advertising (https://stackoverflow.co/advertising/employer-branding/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=footer&utm_content=talent) Talent (https://stackoverflow.co/) Company (https://stackoverflow.co/) About (https://stackoverflow.co/company/press/) Press (https://stackoverflow.co/company/work-here/) Work Here (https://stackoverflow.com/legal) Legal (https://stackoverflow.com/legal/privacy-policy) Privacy Policy (https://stackoverflow.com/legal/terms-of-service/public) Terms of Service (https://stackoverflow.com/contact) Contact Us Your Privacy Choices (https://policies.stackoverflow.co/stack-overflow/cookie-policy) Cookie Policy (https://stackexchange.com/) Stack Exchange Network (https://stackexchange.com/sites#technology) Technology (https://stackexchange.com/sites#culturerecreation) Culture & recreation (https://stackexchange.com/sites#lifearts) Life & arts (https://stackexchange.com/sites#science) Science (https://stackexchange.com/sites#professional) Professional (https://stackexchange.com/sites#business) Business (https://api.stackexchange.com/) API (https://data.stackexchange.com/) Data (https://stackoverflow.blog/?blb=1) Blog (https://www.facebook.com/officialstackoverflow/) Facebook (https://twitter.com/stackoverflow) Twitter (https://linkedin.com/company/stack-overflow) LinkedIn (https://www.instagram.com/thestackoverflow) Instagram Site design / logo © 2025 Stack Exchange Inc; user contributions licensed under (https://stackoverflow.com/help/licensing) CC BY-SA . rev 2025.10.6.34876 By continuing to use this website, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our (https://policies.stackoverflow.co/stack-overflow/cookie-policy/) Cookie Policy . By exiting this window, default cookies will be accepted. To reject cookies, select an option from below. Necessary cookies only Customize settings