Answers for "get docker container id"

3

docker ps only show names

docker ps --format '{{.Names}}'
Posted by: Guest on August-27-2020
1

get docker id from name

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, 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
Posted by: Guest on October-13-2021
2

list stopped containers

docker ps --filter "status=exited"
Posted by: Guest on May-27-2020
0

get docker container id bash

# The inspect command returns a json, so you can navigate it with
# that logic. 

docker inspect --format '{{.Id}}' [container_name | container_id]

# When you run this: 
docker inspect --format '{{.NetworkSettings.Networks}}' mysql
# You'll get:
map[bridge:0xc00011a000]

# This means it is an iterable, so:
docker inspect --format '{{range .NetworkSettings.Networks}} IP is: {{.IPAddress}} {{end}}' mysql

# Please notice Keyword range at the beginning and {{end}} at the end.
# Anything in between, even plain text, will be printed!
Posted by: Guest on July-23-2021

Browse Popular Code Answers by Language