LF Docker first aid kit

Before start, did you check github docker image builds for errors?, if the image couldn’t be created github logs outputs useful information.

For purposes of this document, we will define Docker log as the Docker and a container running command STDOUT, STDERR.

Host general stats

You can check host general stats running top command, or htop (prefered) if installed. Any of those commands will show memory and cpu usage by the overall server, it is possible to run it before deploying to check if memory reaches its limits on build time.

$top

Get Docker general stats

This command will show useful information like CPU% , MEM%, access to disk and network for all running containers.

$docker stats

Get containers information

Get containers running containers basic information. With this command we can get the container’s ID, NAME, PORTS and other basic information.

$docker ps

Get containers basic information, including stopped ones

Get container’s logs

Following command works for both running and stopped containers

All containers from a compose file:

Specific container:

Latest lines of log

You can get only the 20 latest lines of the log adding | tail -20 to any of the commands above. For example:

Docker log on real-time for a running container

Docker-compose file for LF is ran on detach mode, meaning that there is no terminal showing containers output, you can access that log as described above, but you might also want to view it on real-time to see its reactions to actions executed elsewhere (e.g. the browser). For this you can attach the container to a terminal on the host with the following command:

you can then exit with Ctrl+C.

Execute commands on running container

After this command you get a terminal on the running container, you could use it to read internal logs, check files, or any other command available inside the container (not host commands)

if you want to know top running containers you could just:

Copy files (or folders) from and to a container

This works both for running and stopped containers:

from container to host

the command above will copy file.txt to the folder where the command was run with the name file.txt

from host to container

the command above will copy the .env file on the current directory to the specified path on the container.

List and inspect docker objects

Some objects that you might want to list and inspect are networks, named volumes, images or containers. Inspect command will show metadata, connections, and other general information in json format.

You can list host existing networks, and then inspect one by running:

You can list named volumes, and then inspect one by running:

You can list images, and then inspect one by running:

You can list containers, and then inspect one by running: