4.2k views
5 votes
What command is used to print the last 25 lines of the indicated container 'myweb'?

a) docker logs --tail 25 myweb
b) docker container logs --tail 25 myweb
c) docker inspect --tail 25 myweb
d) docker cat --tail 25 myweb

User Ponzao
by
8.0k points

1 Answer

6 votes

Final answer:

The correct command to print the last 25 lines of a Docker container named 'myweb' is 'docker container logs --tail 25 myweb'. Both 'docker logs' and 'docker container logs' are valid, with the latter being more explicit and the former working in older Docker versions.

Step-by-step explanation:

To print the last 25 lines of the logs from the indicated Docker container named 'myweb', the correct command to use is:

b) docker container logs --tail 25 myweb

The docker logs and docker container logs commands are used to fetch the logs of a container. Here, the --tail flag is utilized to limit the output to the last 25 lines. This can be very useful for troubleshooting issues with containers by observing their recent activity logs without having to parse through the entire log history.

Option a) is also correct assuming you have an older version of the Docker client which allows the shorthand docker logs instead of the full docker container logs command.

User Rajitha Bhanuka
by
7.4k points