Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exact times in "docker ps" and "docker images"

Tags:

docker ps and docker images express times in a rather vague fashion, e.g. "About an hour ago" or "2 days ago". How can I discover the exact times?

like image 278
mhsmith Avatar asked Jan 28 '15 22:01

mhsmith


People also ask

What is difference between docker ps and docker?

There is no difference between the docker ps (docker process status) and docker container ls (docker container list) commands in terms of functionality. They even allow the same set of flags. The only real difference between the two is the fact that the latter is newer and more verbose than the former.

What does ps in docker mean?

ps means “Process Status”, so docker ps basically shows all of the Docker processes actively running. docker ps lists all containers that are up and running.

Does docker images have a different state and change with time?

An image can never change. So, if you get your Docker virtual machine into a working state and create an image, you know that image will always work, forever. This makes it easy to try out additions to your environment. You might experiment with new software packages, or try to reorganize your project files.

How does docker container get time?

Docker containers always use the system clock of the host machine but it sets its time-zone as UTC.


2 Answers

Use docker inspect:

docker inspect -f '{{ .Created }}' IMAGE_OR_CONTAINER
like image 65
jwodder Avatar answered Sep 29 '22 07:09

jwodder


The question is asking how to display the exact times when using docker ps and docker images. This can be accomplished directly with a format argument, using CreatedAt

$ docker ps --format 'table {{.ID}}\t{{.Command}}\t{{.CreatedAt}}'
CONTAINER ID        COMMAND                  CREATED AT
86baa3a5058a        "./env.sh catalina.s…"   2019-10-30 08:30:15 -0400 EDT   
1eb21e95119d        "./env.sh catalina.s…"   2019-10-30 06:58:34 -0400 EDT   
87be4be4c328        "docker-entrypoint.s…"   2019-10-30 06:58:33 -0400 EDT   
e4ab699631c8        "./env.sh catalina.s…"   2019-10-30 06:58:32 -0400 EDT   

The table specification adds the headers. The legal format fields are documented, for example at https://docs.docker.com/engine/reference/commandline/ps/#formatting, but mostly correspond to the capitalized column headers, so you could add {{.Ports}} to the format above.

docker inspect (from this answer https://stackoverflow.com/a/28203469/500902) can be used to display the time for a single image or container, uses a different format property {{.Created}} and displays the time format slightly differently, for no obvious reason.

like image 24
Marvin Avatar answered Sep 29 '22 06:09

Marvin