COPY in Dockerfile does not work

0 votes

Hi everyone,

I want to change my hostname throgh the Dockerfile copying a local file hosts in /etc/hosts but does not work.

This is my Dockerfile:

FROM  ubuntu

RUN apt-get update && apt-get install -y bind9 bind9utils bind9-doc

COPY hosts /etc/hosts
COPY named.conf.local /etc/bind/named.conf.local

The file called named.conf.local is successfully copied in my container while hosts file not. Anyone knows the problem?

Thank you.

Mar 18, 2020 in Docker by anonymous
• 120 points
2,711 views
Instead Copy, you can try CMD cat hosts >> /etc/hosts;
Should be permission issue
replacing the hosts file does not change your hostname. why do you want to change the hostname at all?

3 answers to this question.

0 votes

Your query is similar to https://www.edureka.co/community/7415/copy-is-not-working-in-docker Check this out!

answered Mar 18, 2020 by Sirajul
• 59,230 points
0 votes
1. RUN hostname new-server-name

2. RUN echo "new-server-name" >> /etc/hostname

3. RUN echo "127.0.0.1 new-server-name" >> /etc/hosts?
answered Mar 19, 2020 by Anton skosyrev
0 votes
You cannot overwrite /etc/hosts in a docker container. That file is exclusively managed by the docker daemon. You can, however add host entries with the extra-hosts instruction. These hosts are then used to generate the hosts file when the container starts up.
answered Mar 19, 2020 by Thomas Baumann

Related Questions In Docker

+1 vote
4 answers

COPY is not working in Docker

I had the exact same issue. I ...READ MORE

answered May 6, 2019 in Docker by Emilia
22,363 views
0 votes
1 answer

How does mixing Swarm and Kubernetes work in the same cluster?

Yes you could use them together. When you ...READ MORE

answered Jul 5, 2019 in Docker by Sirajul
• 59,230 points

edited Jul 6, 2019 by Sirajul 2,340 views
+2 votes
1 answer
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,020 points
2,720 views
0 votes
1 answer

How does save and export command work in docker and how are they different from one another?

Export : Export is used to persist a ...READ MORE

answered Jul 2, 2019 in Docker by Sirajul
• 59,230 points

edited Jul 2, 2019 by Sirajul 6,969 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP