I have hbase instance running which my app connects, We are planning to move the app into docker container but keep hbase running outside of docker. I could make the my app running in docker container connect to hbase by using add-host option while running docker container as below
docker run -dit --add-host hbasehost:xxx.xxx.xxx.xxx mydockerimage
However what we need is auto-scaling function of swarm, as we have multiple services to run, what is the correct way of achieving this if i want to run my app as docker service instead of individual container, i couldn't find any references to "--add-host" in "docker service"
Update: As of docker
1.13
you now have a similar flag to add entries to/etc/host
.
To add a host at service creation, you can use the --host
flag:
docker service create --name myapp --host "hbasehost:xxx.xxx.xxx.xxx" --replicas 5 myimage
To update the service and add an additional host after its creation, you use the --host-add
flag:
docker service update --host-add "hbase:x.x.x.x" myapp
You can also remove a host using --host-rm
.
--add-host
only appends an host:IP
association in /etc/hosts
.
You can switch from using --add-host
to using environment variables with --env
even though this will require slight changes to your app to use the environment variable instead of the hostname to connect to hbase.
# Applies environment variables for all tasks in a service.
docker service create --name myapp --replicas=5 --env HBASEHOST=xxx.xxx.xxx.xxx myimage
Then you can scale the service using:
docker service scale myapp=20
Additional tasks should be able to use the environment variable to connect to hbase.
Source: I'm an ex-Docker Swarmkit maintainer