none
How to gain windows container id in windows container? RRS feed

  • Question

  • How to gain windows container id in windows container like linux container get container-id using /proc/self/cgroup ?
    Thursday, April 6, 2017 9:40 AM

All replies

  • I'm not sure how you are trying to manage your container

    To get the container-id of a container I'm running I just use a command prompt and type "docker ps".

    In general we are trying to make the management experience for linux and windows containers similar - does this work for you?

    • Proposed as answer by Myles Keating Wednesday, April 12, 2017 6:07 PM
    Tuesday, April 11, 2017 7:24 PM
  • I want to gain the container id in the container self. For example, I run a windows container with name foo. And docker exec -it foo powershell, then in the container foo, how can I get the container id?
    Thursday, April 13, 2017 8:53 AM
  • Ah ok thanks for clarifying!

    Here's a great thread

    http://stackoverflow.com/questions/20995351/docker-how-to-get-container-information-from-within-the-container

    Looks like there's 2 options.  The fully supported, more durable option is to use the Docker Engine API: https://docs.docker.com/engine/api/

    The quicker, more hacky solution is to inspect the container hostname: run: docker inspect $(hostname) inside the container.

    This apparently fails in certain scenarios, not sure when or why.

    Wednesday, April 26, 2017 6:52 PM
  • Isn't the main goal to run app within container is to abstract it from the executing environment? What gain do you have to know container id where your app is running in? Take into account that it may run in multiple containers and even on different hosts.

    Can you explain the usage of the container id?

    Thursday, April 27, 2017 7:30 AM
  • "Isn't the main goal of containers abstracting a process from the executing environment?"

    Yes, this is one major goal.  Also efficiency, scalability, speed of dev/test cycle, and developing more modular software architecture (breaking an app or service into smaller pieces)

    "What can I gain from knowing the container id?"

    Lots of things - performance monitoring, logging, diagnosing and debugging issues, to perform actions on or with the container, differentiating between running containers, etc.

    Let me know if you're having any issues and I'll do my best to answer questions and help you out :)

    Thursday, April 27, 2017 6:35 PM