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 17 in Docker by anonymous
• 120 points
312 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 by Sirajul
• 57,940 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 18 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 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
7,622 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
• 57,940 points

edited Jul 5, 2019 by Sirajul 478 views
+2 votes
6 answers

copy directories in docker container excluding any one directory

One of the way could be copy ...READ MORE

answered Dec 10, 2018 in Docker by Prateek
13,924 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
• 57,660 points
780 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
• 57,940 points

edited Jul 2, 2019 by Sirajul 328 views
0 votes
1 answer