Sobes.tech
Junior — Middle

How to determine the ID of the first launched container in Docker?

sobes.tech AI

Answer from AI

To determine the ID of the first started container in Docker, you can get a list of all containers with their start times and sort by the start date. For example, the command:

docker ps --format "{{.ID}} {{.CreatedAt}}" | sort | head -n 1 | awk '{print $1}'

This command will output the ID of the container with the earliest creation date among running containers. Alternatively, you can get all containers (including stopped ones) and select the first by creation time:

docker ps -a --format "{{.ID}} {{.CreatedAt}}" | sort | head -n 1 | awk '{print $1}'

Thus, the ID of the first started container is the ID with the earliest creation date.