Docker Community Forums

Share and learn in the Docker community.

Can I add add-host to /etc/default/docker?

(Morvenhuang) #1

Hi all,

I’m new in Docker, here is the docker version info:

Client version: 1.5.0
Client API version: 1.17
Go version (client): go1.4.1
Git commit (client): a8a31ef
OS/Arch (client): linux/amd64
Server version: 1.5.0
Server API version: 1.17
Go version (server): go1.4.1
Git commit (server): a8a31ef

And the host is Ubuntu, version:
Linux mh-docker1 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

What I’m trying to do is to add a line to container’s hosts file, I can do this without any problem via command line:
sudo docker run -it --add-host centos:mhtest

But I don’t want to do this every time in the command line, so I update /etc/default/docker, add

After this change, I restart docker by “sudo service docker restart”.
Then I “ps aux|grep docker”, but there’s no docker process, it seems docker fails to start up.

So I wonder to know if this option add-host can be added to /etc/default/docker?

(Jerry Baker) #2

DOCKER_OPTS is used to modify the Docker daemon startup options, not any container launches.

You could create a helper function with your defaults to launch. - Here’s an example for bash (in ~/.bashrc):

function drun {
  docker run -ti --add-host $*

Then when you run it:

ubuntu@ubuntu:~$ drun ubuntu bash
root@16d790f29762:/# cat /etc/hosts      16d790f29762       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters