Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker apache image, store logs in host?

I use Docker to build an Apache image, and then use docker-compose to run it. I set up Apache access.log and error.log and want to store them outside of the container. currently, I use Volumes but it stores the data both in container and host.

docker-compose.yml

version: '2'

services:
  web:
    image: apache
    build: .
    container_name: my-image
    volumes:
        - "/var/log/my-app:/var/log/apache2"
    restart: always
    ports:
      - "8000:80"

My question is how to only store apache log data in a host, and It woule be better if there is a way to stream apache log data to stdout so that I don't need to store in the host.

Thanks in advance!

like image 855
Fujiao Liu Avatar asked Mar 10 '26 19:03

Fujiao Liu


2 Answers

Volumes but it stores the data both in container and host.

Not really, it should only store data in the host (and makes it visible in the container through a bind mount)

if there is a way to stream apache log data to stdout

Possible yes, through configuration, but that would not be persistent.

like image 117
VonC Avatar answered Mar 12 '26 09:03

VonC


Check this post for the Apache configuration:

https://serverfault.com/questions/711168/writing-apache2-logs-to-stdout-stderr

Then you can inspect your logs with

docker logs <container>
like image 37
Mihai Avatar answered Mar 12 '26 07:03

Mihai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!