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

  • How to get docker container name in java code
  • How to downgrade Docker on Mac to 1.12.x or connect to 1.12 hosts from 1.13 in Mac?
  • Error running gitlab-ci.yml script under Alpine Docker based Image
  • Why doesn't my pod respond to requests on the exposed port?
  • REST request from one docker container to another fails
  • Variable substitution not working on Windows 10 with docker compose
  • docker-compose.yml:

      command: python -u 
        - /workspace:/app
      command: echo -e "POST /containers/containerA/kill?signal=SIGUSR1 HTTP/1.0\r\n" | nc -U /tmp/docker.sock

  • How to connect to mysql using ipv6 from wordpress
  • Digital ocean kill the build process on docker
  • Is there any way to override the “network/ipc” container in the kubernetes pod declaration?
  • docker internet connectivity with iptables=false
  • Writing Dockerfile for Dockerhub Automated builds
  • PyMongo and Django
  • 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...]
       -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.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.