0

I think I am doing something a bit too convoluted and hence probably wrong.

So I want to change the /etc/hosts file and to do that, I changed the entrypoint in the Dockerfile to something like

ENTRYPOINT ["/bin/sh", "-c", "echo \"10.0.0.1 some_pc\" >> /etc/hosts && exec \"$@\""]
CMD ["some_reasonable.sh"]

If I set my something_reasonable.sh to do something useful it, it runs, but if I want to start again the docker image with an interactive shell it just exits. Moreover, if I try to execute a command with arguments, it treats it as 2 commands.

I think there is something wrong with the way I am treating shell and scripts. Probably, putting the exec line like this is not the same as putting in a script (like What does set -e and exec "$@" do for docker entrypoint scripts?)

So how can I write this ENTRYPOINT one-liner so that docker-run -it my_docker:latest bash gives me back my interactive session?

user27221
  • 334
  • 3
  • 16
  • Do you actually want [docker run --add-host](https://docs.docker.com/engine/reference/run/#managing-etchosts)? – David Maze Oct 02 '18 at 16:12
  • No, I don't. I did the normal workaround everyone does and used an entrypoint.sh script to write this, but I already have around 8 installation scripts just for this docker image and having to load it with a bunch of options is also rather inconvenient. I was just looking for an one-liner that would do something similar to what the entrypoint.sh script does and have me avoid at least this one – user27221 Oct 04 '18 at 14:58
  • Probably the correct solution here is to use the docker-compose and add the hosts there; but what I would like is to know how to make this ENTRYPOINT line work. From this post http://www.johnzaccone.io/entrypoint-vs-cmd-back-to-basics/ it seems the CMD value is just prepended to ENTRYPOINT, but I still don't know how I can use this knowledge to get back my interactive session working – user27221 Oct 04 '18 at 15:09

0 Answers0