Docker Community Forums

Share and learn in the Docker community.

Order of containers in docker ps

I believe docker ps lists the containers in a chronological order of their creation (newest to oldest).

Can someone please confirm this? I’m writing a library and I need to pick the latest container. I am currently doing that by listing the container ids and picking the first one.
docker ps -a -f --format '{{.ID}} | awk 'NR==1'
Is this guaranteed to pick up the latest container? If not, what is the right way to do it?