docker-compose get ID of a docker
I am using docker-compose, with a docker-compose.yml file.
Is there a way to get in .yml, the ID of another docker (which is in the same docker-compose.yml)?
containerA: command: python -u catch_sig.py volumes: - /workspace:/app containerB: command: echo -e "POST /containers/containerA/kill?signal=SIGUSR1 HTTP/1.0\r\n" | nc -U /tmp/docker.sock
3 Solutions collect form web for “docker-compose get ID of a docker”
With newer docker-compose versions (I have 1.8.0) you can do
$ docker-compose ps -q
Which will only display the id.
See the usage.
$ docker-compose ps --help List containers. Usage: ps [options] [SERVICE...] Options: -q Only display IDs
Not sure about the .yml file but if you link the containers you can get the ID from
/etc/hosts as written in the docs. Maybe this will be helpful.
You can add the Docker client to containerB and then set the DOCKER_HOST environment to the underlying host (be sure to configure its settings so it accepts TCP connections on the network). Then, you can do a
docker inspect containerA using the container name to identify the host you are querying.
This should give you the container id for containerA.