Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)?

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
like image 887
pierrelb Avatar asked Jun 16 '15 14:06

pierrelb


People also ask

How do I find the id of a docker container?

Find the running container's ID by using the docker ps command. Find the PID number of the first process in the running container by running the docker inspect command. Enter the running container by using the nsenter command.

How do I find the docker image name?

The easiest way to list Docker images is to use the “docker images” with no arguments. When using this command, you will be presented with the complete list of Docker images on your system. Alternatively, you can use the “docker image” command with the “ls” argument.

How do I list a docker container?

In order to list the Docker containers, we can use the “docker ps” or “docker container ls” command. This command provides a variety of ways to list and filter all containers on a particular Docker engine.


2 Answers

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
like image 147
VolkerK Avatar answered Oct 06 '22 13:10

VolkerK


You can get the ID of a container in this way:

docker-compose ps -q [container-name]
like image 43
Eugenio Carocci Avatar answered Oct 06 '22 12:10

Eugenio Carocci