0

I have two docker containers on my local machine from my two spring boot applications

  1. Eureka discovery client (discovery )
  2. My service (validation )

I have to register myservice with Eureka client. I am able to do it when I run these two spring boot applications on my local. But when I create a image It is not linking.

docker run -d -p 7070:7070 -t --name validation --link discovery docker-crst/bosng_validationsservice

docker run -d -p 8761:8761 -t --name discovery docker-crst/discovery-service
Shahriar
  • 13,460
  • 8
  • 78
  • 95
Rohit
  • 51
  • 1
  • 9
  • If the above is the order in which you create you containers then why would you expect validation to know about discovery if it is not running yet? – Oleg Sklyar Mar 03 '18 at 08:26
  • Try start the container discovery first then validation. You can't link to a not-running container. Or, you can create a network for these 2 containers, then the order in which you start containers wouldn't matter any more. – Yun Luo Mar 03 '18 at 08:44

1 Answers1

0

As per the docker documentation, the links feature is deprecated and shouldn't be used anymore. Instead, the approach of creating a bridge network and attach the containers to that network should provide the docker container reference by name out of the box.

By default, docker creates a network bridge called docker0 that is joined automatically by all the containers on that host. If however you create your own bridge network and add your containers to that network, they can be referenced by name between them out of the box. See the docker documentation in that case: https://docs.docker.com/network/bridge/#differences-between-user-defined-bridges-and-the-default-bridge

In your case, this would be:

$> docker network create test01
$> docker run -d -p 7070:7070 -t --net test01 --name validation docker-crst/bosng_validationsservice
$> docker run -d -p 8761:8761 -t --net test01 --name discovery docker-crst/discovery-service

In this example, the two containers can reference each other by name.

nucatus
  • 2,196
  • 2
  • 21
  • 18