In the previous page, you have understood basic management of a docker container and what you need to run, pause, stop a container. Now, we will discuss container logs and process management in Docker. Docker provides a few commands to view container information without using
exec commands. Will be also looking into how to achieve resource limitation.
View Docker Container logs
Docker provides docker logs command to fetch logs of a container.
docker logs [OPTIONS] CONTAINER
- To view logs in real time,
--follow) continues streaming the new output that container provides.
- The command
docker logs --detailsadds extra attributes, such as environment variables and labels, provided to
--log-opt when creating the container.
--sincethe option shows only the container logs generated after a given date.
- The docker logs
--timestampscommand will add an RFC3339Nano timestamp , for example
2019-06-16T06:17:46.000000000Z, to each log entry. To ensure that the timestamps are aligned the nano-second part of the timestamp will be padded with zero when necessary.
I encourage you to try out the above commands and let me know your challenges in the comment below.
Docker container process information
docker top and
docker stats to get information about the running processes inside a Docker container.
top command lists the processes running within a container.
docker top CONTAINER [ps OPTIONS]
As you can see in the below terminal output, there are 2 processes running in the nginx container.
Display a live stream of container(s) resource usage statistics.
docker stats [OPTIONS] [CONTAINER...]
Resource limitation for a docker container
I have not explained to you about resource limitation, but that is the reason why you learning docker. You want to achieve resource isolation as well as assign a certain amount of CPU Core, RAM or Memory to a running container.
- While launching a container using
docker run, you can do the following
- However, if you already have the container running, use
docker updateto update the configurations.
docker update [OPTIONS] CONTAINER [CONTAINER...]
This is a short guide page I explained container logs and process management, move to the next section explaining about data/volume management in Docker.