If you have two applications and one database in a stack then the docker-compose.yml file looks like this
version: "3.3"
services:
app1:
image: custom-image-app1
ports:
- "8000:8000"
app2:
image: custom-image-app2
ports:
- "8080:8080"
db:
image: postgres:17
environment:
POSTGRES_DB: mydatabase
POSTGRES_USER: myuser
POSTGRES_PASSWORD: mypassword
ports:
- "5432:5432"
Let's say you have an update only in one application. How do you update the stack? If you run
docker stack down my_stack
docker build . -t my-app
docker stack up -c docker-compose.yml my_stackthen you are doing everything wrong!
After building a new image (or pulling it from the registry) you can update only the specific service with this command
docker service update --force --update-parallelism 1 --update-delay 5s my_stack_app1But if you only need to add an environment variable
docker service update --env-add ALLOWED_HOSTS=mastodon my_stack_app1
# and verify that it's there
docker service inspect --format "{{ .Spec.TaskTemplate.ContainerSpec.Env }}" my_stack_app1About logs
Check logs like this
docker service logs -f my_stack_app1Set log rotation by editing /etc/docker/daemon.json
{
"log-driver": "local",
"log-opts": {
"max-size": "10m"
}
}Reference: https://docs.docker.com/config/containers/logging/local/
You can check if the logs grow abundantly on your drive1
du -h $(docker inspect --format='{{.LogPath}}' $(docker ps -qa))And possibly then archive them
docker inspect --format='{{.LogPath}}' $(docker ps -qa) | xargs -I{} sh -c 'gzip -c "{}" > "./$(basename "{}").gz"'And delete... (careful one by one version)
sudo sh -c 'echo "" > $(docker inspect --format="{{.LogPath}}" e430578d8809)'But do not do this type of deletion! It will break the output from the log command. You could still read logs from raw JSON:
sudo tail -n 50 -f /var/lib/docker/containers/e430578d8809005f7756606fc8e765a88813f1b17a59e23b19c8320758d70f46/e430578d8809005f7756606fc8e765a88813f1b17a59e23b19c8320758d70f46-json.log | jq -j '.["log"]'I even managed to make a combined version when in a docker stack one service has several instnaces (search by the service name)
tail -qf $(docker inspect --format="{{.LogPath}}" $(sudo docker ps -f name=<your service name> -q)) | jq -j '.["log"]'