Search code examples
dockerdockerfilejaeger

Link docker containers in the Dockerfile


I have a Jaeger running in a docker container in my local machine.

I've created a sample app which sends trace data to Jaeger. When running from the IDE, the data is sent perfectly.

I've containerized my app, and now I'm deploying it as a container, but the communication only works when I use --link jaeger to link both containers (expected).

My question is:

Is there a way of adding the --link parameter within my Dockerfile, so then I don't need to specify it when running the docker run command?


Solution

  • There is no possibility of doing it in the Dockerfile if you want to keep two separate image. How should you know in advance the name/id of the container you're going to link ?

    Below are two solutions :

    1. Use Docker compose. This way, Docker will automatically link all the containers together
    2. Create a bridge network and add all the container you want to link inside. This way, you'll have name resolution and you'll be able to contact each container using its name