Get docker container id from container name

后端 未结 9 1677
無奈伤痛
無奈伤痛 2020-12-12 11:48

What is the command to get the docker container id from the container name?

9条回答
  •  难免孤独
    2020-12-12 12:07

    In Linux:

    sudo docker ps -aqf "name=containername"
    

    Or in OS X, Windows:

    docker ps -aqf "name=containername"
    

    where containername is your container name.

    To avoid getting false positives, as @llia Sidorenko notes, you can use regex anchors like so:

    docker ps -aqf "name=^containername$"
    

    explanation:

    • -q for quiet. output only the ID
    • -a for all. works even if your container is not running
    • -f for filter.
    • ^ container name must start with this string
    • $ container name must end with this string

提交回复
热议问题