How to use the 1st container when you are standing inside the 2nd container?

Hi all, I’m new on Docker and got some stuck when using it.

I have 3 containers, one is PHP, one is Composer and the other is Jenkins. When Jenkins completed clone source code from git, it needs to run composer but the composer is running in the other container, how can I use the composer when I’m standing on Jenkins container?

So the general question is “how to use the 1st container when you are standing inside the 2nd container?”

the 1st container needs to know the ip address of the second container somehow, and some interaction mechanism, api, ssh, ??? something…

with the docker-compose application you can setup a multi-container solution, and a locally defined network where the names mostly work…

then the containers can use DNS like names…

without compose (using=jenkins, used=composer)

you docker run the used containers first, get their ip addresses and then on the using container use the --add-host parm of docker run to add the used container hostname and ipaddress to the using containers /etc/hosts file… then use the dnslike hostname to conncet to the used container

1 Like

Thanks! But the Composer isn’t running as a service (https://hub.docker.com/r/composer/composer/). so I can’t communicate with Composer when I’m standing inside Jenkins container. Eg: I want to use this command “docker run --rm -v $(pwd):/app composer/composer install” when I’m standing inside Jenkins container.

yes, SO, you need

docker run --rm -v $(pwd):/app --add-host **composer_name:composer_ip** composer/composer install”

Ya, you make my day bro! Thank you so much