大网数据广告活动
服务器运维问答

Apache in Docker: How do I "access.log"?

· 52CE 我爱测

I'm just getting started with Docker and richt now I'm trying to figure out how to set up my first dockerized Apache 2 / PHP environment. Up to now I have been using full Linux VMs, where I used log-files being written to /var/lo…

问题原文

原帖链接 · BlaM · CC BY-SA 3.0

I'm just getting started with Docker and richt now I'm trying to figure out how to set up my first dockerized Apache 2 / PHP environment. Up to now I have been using full Linux VMs, where I used log-files being written to /var/log/apache2, then use "logrotate" to hop to a new file each day.

Logfiles were mainly used for immediate error detection (i.e. log on to the server and use less to open the current access.log and error.log files) and for fail2ban.

If I'm correct that is not practicable in an Docker environment - mainly because you usually cannot log in to containers to have a look at the logs. Also logs will be lost if the container is removed.

So: What is the most common method to work with/emulate/replace access.log/error.log in that situation? What are common solutions for both production and development environments?

My ideas so far include using a NFS share (slow and may cause filename collisions if not careful), and logstash (not sure if it is worth the effort and practicable for smaller sites or even dev environments?) but I'm sure smart people have come up with better solutions?

Not sure if it makes a difference, but currently I'm basing my Docker image on php:5.6-apache.

社区高分解答

原帖链接 · Fony Lew · CC BY-SA 3.0

You can still use docker exec -it <your container name> /bin/bash command to get into your container and do your regular job. Or maybe you can change /bin/bash into your command or script .sh of your command to execute it.

To get your file out of container use docker cp <container name:/path/to/file> </your local machine/path/>

And for your daily job, you can use cron to cronjob those commands. I highly reccommend you to have alias your frequent docker commands. So that I can use docker happily with a few key.

The docker logs <container name/id> command is for viewing log from execution of the docker image. It shows redirect output to stdout.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-03-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。