Index ¦ Archives ¦ Atom

Add an additional host entry to docker container


Let's say a program in a container should be able to resolve a custom hostname.


When using docker run:

$ sudo docker run --add-host -ti python bash
Unable to find image 'python:latest' locally
latest: Pulling from library/python
Digest: sha256:eb20fd0c13d2c57fb602572f27f05f7f1e87f606045175c108a7da1af967313e
Status: Downloaded newer image for python:latest

This will show up as an additional entry in the container's /etc/hosts file:

root@fee9aeccbc4b:/# cat /etc/hosts

With docker compose, we can use the extra_hosts key:

    - ""

Share on: Diaspora*TwitterFacebookGoogle+Email

© Amit Saha. Built using Pelican. Customised theme based on the one by Giulio Fidente on github.