Docker: connecting to an external database

I have a running hbase instance that my application is connecting to. We plan to move the application to the docker container, but hbase will work outside the docker. I can force the application connected to the docker container to connect to hbase using the add-host option while the docker container is running, as shown below

docker run -dit --add-host hbasehost:xxx.xxx.xxx.xxx mydockerimage 

However, we need a swarm auto-scale function, since we have several services to start, which is the right way to achieve this, if I want to run my application as a docker service instead of a separate container, I could not find links to "-add-host" in docker service

+7
docker hbase docker-swarm
source share
2 answers

Update : with docker 1.13 now have a similar flag for adding entries to /etc/host .

To add a host when creating a service, 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 creating it, use the --host-add flag:

docker service update --host-add "hbase:xxxx" myapp

You can also remove the host using --host-rm .


Original answer

--add-host only adds the host:IP association to /etc/hosts .

You can switch from --add-host to environment variables with --env , although this will require minor changes in your application to use the environment variable instead of the host name 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 an environment variable to connect to hbase.

Source : I am a third-party assistant to Docker Swarmkit

+4
source share

If you pointed your docker hosts to an internal dns server or dns server to which you can create entries, you can create an A record for your hbasehost on the dns server . The containers will use Internal Docker DNS , and then return to hosts DNS Server Settings . But having set the entry in /etc/hosts , do the job (airing).

My docker swarm node resolv.conf :

 nameserver 10.110.1.25 nameserver 10.110.1.26 

Now check inside one of the containers:

 root@05d05f934c68 :/# ping dc1.mydomain.net PING dc1.mydomain.net (10.110.1.25): 56 data bytes 64 bytes from 172.20.21.5: icmp_seq=0 ttl=121 time=0.929 ms 
+2
source share

All Articles