Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
Access logs outside docker containers

I run an algorithm using the command "docker-compose up" on a cloud server. One of the services (productionbackend) writes logs as part of its execution, in a location inside its container (./logs/Log_< UTCTIMENOW >.txt).

I know I can use the 'docker logs' command to inspect logs when the service runs, but once it is stopped using 'docker-compose down', logs are lost forever (as the container is destroyed).

So I guess I would like to 'mount' a volume to my docker compose file, and redirect the output of that log.txt file to the ~ directory, outside the container. This is what my directory tree looks like:

I tried all kind of combinations in the docker compose file, without success.

For instance, adding the below failed.

volumes:
- type: volume  # Also tried `bind` type and other syntaxes
- ./logs:/productionbackend/logs


.
├── docker-compose.yaml #THIS IS THE DOCKER-COMPOSE FILE STARTING MY SERVICES
├── productionfrontend
│   ├── Dockerfile
│   ├── app
│   │   ├── database.py
│   │   ├── main.py
│   │   └── requirements.txt
│   └── docker-compose.yaml
└── productionbackend
    ├── Dockerfile
    ├── backend.py
    ├── logs
    │   ├── Log_03_Jun_14.18.19_GMT.txt
    ├── requirements.txt
    ├── settings
    │   └── somefile.py
     ........

Thank you.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

For next:

volumes:
- type: volume  # Also tried `bind` type and other syntaxes
- ./logs:/productionbackend/logs

I don't know if it's your typo or others, but it seems this grammar is strange, see official grammar

Next I give a minimal example which could work for your reference:

docker-compose.yaml:

version: '3'
services:
  backend:
    image: alpine
    container_name: my_try
    volumes:
      - ./log_on_host:/productionbackend/logs
    command: sh -c 'echo "hi" > /productionbackend/logs/my_log.txt'

And next is the execution history:

shubuntu1@shubuntu1:~/abc$ ls
docker-compose.yaml
shubuntu1@shubuntu1:~/abc$ docker-compose up -d
Creating network "abc_default" with the default driver
Creating my_try ... done
shubuntu1@shubuntu1:~/abc$ docker-compose down
Removing my_try ... done
Removing network abc_default
shubuntu1@shubuntu1:~/abc$ ls
docker-compose.yaml  log_on_host
shubuntu1@shubuntu1:~/abc$ cat log_on_host/my_log.txt
hi

From above, you can see although the container my_try has been destroyed, we still can see the log my_log.txt which has the content hi on host. You need to modify yours similar like above minimal example, just FYI.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!