How to reduce output in `docker-compose` up command - docker

I'm looking for a way to reduce the output generated by docker compose up.
When running in CI all the "interactive" output for download and extract progress is completely useless and generate lots of useless text.
docker has --quiet but I don't see the same for docker compose.

There is a --quiet-pull option that lets you reduce the output generated docker compose up and docker compose run
docker compose up --quiet-pull

You can always run the docker compose in a detached mode with the -d parameter and then check logs of the service/container you want with docker logs --follow <container>
There was an option to set the log-level with --log-level [DEBUG, INFO, WARNING, ERROR, CRITICAL] but it is deprecated from version 2.0.

Related

how to run NiFi-toolkit docker image

am trying to start a container for nifi-toolkit, I get the error message No program option specified. Options available include: encrypt-config s2s flow-analyzer node-manager tls-toolkit file-manager notify zk-migrator cli but, am not sure where/how to set these values
Open a terminal and run:
docker run --rm apache/nifi-toolkit file-manager
This is an example for file-manager option. Change it for different options. You can also add parameter(s) after file-manager.
Explanation:
This image has an entrypoint defined. Meaning a program that runs by default when you start a container based on it.
You can see it with:
docker pull apache/nifi-toolkit
docker run --rm --entrypoint cat apache/nifi-toolkit /opt/sh/docker-entrypoint.sh

docker compose command to run with profiles

With the recent update of docker, whenever I run docker-compose up -d docker engine suggest me with the following line:
Docker Compose is now in the Docker CLI, try docker compose up
Question is how can I run docker compose command with profile option?
For example, in docker-compose I can use profiles as docker-compose --profile dev up.
Is there a similar thing in docker compose too?
I looked into the CLI reference but didn't find anything.
docker compose has profile option. Try executing docker compose --help in your terminal and you will see the below help section with the option of profile
╰>>> docker compose --help
Usage: docker compose [OPTIONS] COMMAND
Docker Compose
Options:
--ansi string Control when to print ANSI control characters ("never"|"always"|"auto") (default "auto")
--env-file string Specify an alternate environment file.
-f, --file stringArray Compose configuration files
--profile stringArray Specify a profile to enable
--project-directory string Specify an alternate working directory
(default: the path of the Compose file)
-p, --project-name string Project name
Commands:
build Build or rebuild services
convert Converts the compose file to platform's canonical format
create Creates containers for a service.
down Stop and remove containers, networks
events Receive real time events from containers.
exec Execute a command in a running container.
images List images used by the created containers
kill Force stop service containers.
logs View output from containers
ls List running compose projects
pause pause services
port Print the public port for a port binding.
ps List containers
pull Pull service images
push Push service images
restart Restart containers
rm Removes stopped service containers
run Run a one-off command on a service.
start Start services
stop Stop services
top Display the running processes
unpause unpause services
up Create and start containers
Run 'docker compose COMMAND --help' for more information on a command.
If your docker CLI doesn't have this option maybe you will have to upgrade your docker CLI.
Here is the Docker CLI documentation with --profile option.

How to know which command or compose file has been used to start Docker containers?

Is there any way to find a source of the docker container script? I have a setup where I can not find any docker-compose.yml file nor the bash script etc that would have run all the Docker containers currently running. I have a virtual machine that starts docker containers on the startup, but have no idea which file is actually run.
i think no option to know which docker-compose file is use.
but you can check manual every you project folder.
the docker-compose mechanism is by matching the docker-compose.yml file. so if you run command sudo docker-compose ps in every your project folder. docker-compose will match between the docker-compose file used by container and docker-compose file in your project, if the same than the results will be displayed, if not the results is not displayed
If the containers are running automatically on reboot and you have no cron/bash profile/rc.local or any other startup screen then that may mean that they are containers with --restart option set. You can change that by running below command
docker ps -q | xargs docker update --restart no
docker ps -q | xargs docker stop
Then restart the machine. The containers should not start. If they do then you have some script somewhere which is starting them

How to view log output using docker-compose run?

When I use docker-compose up I can see logs for all containers in my docker-compose.yml file.
However, when I use docker-compose run app I only see console output for app but none of the services that app depends on. How can see log output for the other services?
At the time of writing this the docker-compose run command does not provide a switch to see the logs of other services, hence you need to use the docker-compose logs command to see the logs you want.
Update June 10th 2022
As commented by #Sandburg docker compose is now integrated into docker. As described here most of the docker compose commands can be called the same way just without the dash:
The new Compose V2, which supports the compose command as part of the Docker CLI, is now available.
Compose V2 integrates compose functions into the Docker platform, continuing to support most of the previous docker-compose features and flags. You can run Compose V2 by replacing the hyphen (-) with a space, using docker compose, instead of docker-compose.
Update July 1st 2019
docker-compose logs <name-of-service>
for all services
docker-compose logs
Use the following options from the documentation:
Usage: logs [options] [SERVICE...]
Options:
--no-color Produce monochrome output.
-f, --follow Follow log output.
-t, --timestamps Show timestamps.
--tail="all" Number of lines to show from the end of the logs
for each container.
See docker logs
You can start Docker compose in detached mode and attach yourself to the logs of all container later. If you're done watching logs you can detach yourself from the logs output without shutting down your services.
Use docker-compose up -d to start all services in detached mode (-d) (you won't see any logs in detached mode)
Use docker-compose logs -f -t to attach yourself to the logs of all running services, whereas -f means you follow the log output and the -t option gives you timestamps (See Docker reference)
Use Ctrl + z or Ctrl + c to detach yourself from the log output without shutting down your running containers
If you're interested in logs of a single container you can use the docker keyword instead:
Use docker logs -t -f <name-of-service>
Save the output
To save the output to a file you add the following to your logs command:
docker-compose logs -f -t >> myDockerCompose.log
If you want to see output logs from all the services in your terminal.
docker-compose logs -t -f --tail <no of lines>
Eg.:
Say you would like to log output of last 5 lines from all service
docker-compose logs -t -f --tail 5
If you wish to log output from specific services then it can be done as below:
docker-compose logs -t -f --tail <no of lines> <name-of-service1> <name-of-service2> ... <name-of-service N>
Usage:
Eg. say you have API and portal services then you can do
something like below :
docker-compose logs -t -f --tail 5 portal api
Where 5 represents last 5 lines from both logs.
Ref: https://docs.docker.com/v17.09/engine/admin/logging/view_container_logs/
use the command to start containers in detached mode:
docker-compose up -d
to view the containers use: docker ps
to view logs for a container: docker logs <containerid>
Unfortunately we need to run docker-compose logs separately from docker-compose run. In order to get this to work reliably we need to suppress the docker-compose run exit status then redirect the log and exit with the right status.
#!/bin/bash
set -euo pipefail
docker-compose run app | tee app.log || failed=yes
docker-compose logs --no-color > docker-compose.log
[[ -z "${failed:-}" ]] || exit 1

Print timestamps in Docker Compose logs

I am seeing my web logs with docker-compose logs web, but I would like to add timestamps to those messages, because now they're quite out of context (don't know when did the event happen). I tried docker-compose logs -t web, but it seems Docker Compose is unaware of this flag.
Do you have any idea how can I make timestamps appear in Docker Compose logs?
docker-compose version 1.8.0 supports logs, you can use:
docker-compose logs -t
docker-compose now supports the -t argument, as pointed out by Ittiel.

Resources