Writing line in file via Dockerfile

Hello,

I’m trying to add a line in a file via Docker file for setting up can settings. To do this I used the following command “echo” in dockerfile see: docker - Editing Files from dockerfile - Stack Overflow. But when I reach this file via ssh I can’t see the line that I add. Can someone help me with it ?
Dockerfile:


Ssh:

Building:

Hi @hugo,

You cannot modify the /etc/hosts file during the image build, since the hosts file is maintained by docker on container startup. docker-compose does support the extra_hosts field which you can use to define the extra hosts you want, see: docker-compose.yml fields - Balena Documentation and Compose file version 2 reference | Docker Documentation

From the docker-compose docs, something like the following:

extra_hosts:
  - "somehost:162.242.195.82"
  - "otherhost:50.31.209.229"

Let us know how this works for you!

Regards,
Christina

Hi, following up per my colleague’s previous message. As she said, you cannot modify the /etc/hosts file during the image build since the hosts file is maintained by docker on container startup, but docker-compose does support the extra_hosts field which you can use to define the extra hosts you want. Could you please confirm whether this works for you?

Hi, yes it is thank you for your help !