zendtech / php-zendserver-docker

Dockerized Zend Server
37 stars 28 forks source link

Unable to see logs in Cloudwatch #9

Open eddietorres7373 opened 6 years ago

eddietorres7373 commented 6 years ago

We are currently having an issue that will not allow us to see any Apache or Zend logs via CloudWatch. It seems by going the default route of starting up the docker it takes over all STDout/err even if we symlink the log files.

Is this a know issue or is there a work around?

davidl-zend commented 6 years ago

Are you running the docker image on AWS's ECS? Please provide detailed instructions so I can re-produce the issue and work on a solution.

eddietorres7373 commented 6 years ago

This is run in ECS. We have a container that will launch the docker and do symlinks for Apache log files (/etc/var/log/apache2/access.log and /etc/var/log/apache2/error.log. Here is a sample of what is being launched.

FROM /php54zend70:1.0.0-1.0.0.0
LABEL DESCRIPTION="Docker Image"
LABEL VERSION="1.1.14"

# Passed in arguments
ENV APPLICATION_ENV="latest" \
    ENVIRONMENT=${APPLICATION_ENV:-latest} \
        INSTANCE_NUM="2" \
        PROJECT_VERSION=1.1.14

# Apache Modules - Enable headers and ssl (if local)
RUN a2enmod headers && a2enmod ssl

# Copy application apache port configuration file
COPY docker_config /tmp

# Add Healthcheck
#HEALTHCHECK --interval=5m --timeout=3s CMD curl -f http://localhost/status || exit 1
#HEALTHCHECK --interval=5m --timeout=3s CMD netstat -anp | grep ':80 ' | grep 'LISTEN' || exit 1

# Copy files from Git
COPY src /var/www/html/

# Repoint Zend logs to STDOUT/ERR
RUN mkdir -p /var/www/html/logs \
    && chmod 777 /var/www/html/logs \
    && ln -s /dev/stderr /var/www/html/logs/error.log \
    && ln -s /dev/stdout /var/www/html/logs/standard.log \
    && ln -s /dev/stdout /var/www/html/logs/debug.log \
    && chmod -R 755 /var/www/html/

# Repoint Access/Error logs to STDOUT/ERR
RUN rm -rf /var/log/apache2/* \
    && ln -s /dev/stdout /var/log/apache2/access.log \
    && ln -s /dev/stderr /var/log/apache2/error.log \
    && ln -s /dev/stdout /var/log/apache2/other_vhosts_access.log

# Substitute environment variables
#RUN apt-get install -y gettext-base \
#   && cp /var/www/html/public/.htaccess /tmp/.htaccess \
#        && envsubst < "/tmp/.htaccess" > "/var/www/html/public/.htaccess"

# Expose port 8080
EXPOSE 8080

# Copy the appropriate apache file and start zend server
CMD cp /tmp/apache-${APPLICATION_ENV}.conf /etc/apache2/sites-enabled/application.conf && /usr/local/bin/run
davidl-zend commented 6 years ago

I'll investigate this and try to find a permanent solution. Since each line in a Docker Buildfile is saved in a different layer in the file system, I think the best place for anything that should happen in runtime such as your symlinks is in the "run" script (or anything running in CMD). Another possible option is adding a "tail -f &" in the run script . In apache you can also use "Piped Logs" : https://httpd.apache.org/docs/2.4/logs.html

A more structured approach would be to use docker log drivers: https://docs.docker.com/config/containers/logging/configure/

davidl-zend commented 6 years ago

Can you please provide your application.conf file that's mentioned in your build script so I can re-create your issue? Did my "tail -f" solution help you? Also please note that docker have added a "CloudWatch" log driver.
https://docs.docker.com/config/containers/logging/awslogs/

lokeshmure commented 6 years ago

Here's my application.conf file.

Listen 8080
<VirtualHost *:8080>
    SetEnv APPLICATION_ENV latest
    SetEnv LOG_DIR /var/www/html/logs
    DocumentRoot "/var/www/html"
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <IfModule headers_module>
        Header set X-Environment "latest"
        Header set X-Instance "1"
        Header set X-Version "${project.version}"
        RequestHeader set ZRAY-DISABLE 1
    </IfModule>

    <Directory "/var/www/html">
        Order allow,deny
        Allow from all
        AllowOverride all
    </Directory>
</VirtualHost>

@davidl-zend

davidl-zend commented 6 years ago

Hi,

Can you please provide me with step by step instructions for reproducing the issue?

How is cloudwatch supposed to see the files inside the container?

I'd suggest attaching a docker volume and saving the log files there.

Additionally consider using docker's built-in cloudwatch driver:

https://docs.docker.com/config/containers/logging/awslogs/

Also I notice you are using a very old version of PHP. Unless your app is incompatible with PHP 7 I'd suggest basing your app on php-zendserver:latest

Best regards,

David Lowes | Sr. Cloud Integration Engineer

Zend, a Rogue Wave company

Accelerating Great Code

P +972.3.753.9560 M +972.54.3000.810

www.zend.com / david.lowes@roguewave.com


From: lokeshmure notifications@github.com Sent: Thursday, July 26, 2018 6:42:44 PM To: zendtech/php-zendserver-docker Cc: David Lowes; Mention Subject: Re: [zendtech/php-zendserver-docker] Unable to see logs in Cloudwatch (#9)

Here's my application.conf file. `Listen 8080

<IfModule !headers_module> LoadModule headers_module modules/mod_headers.so

<VirtualHost *:8080> SetEnv APPLICATION_ENV latest SetEnv LOG_DIR /var/www/html/logs

DocumentRoot "/var/www/html" ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined

Header set X-Environment "latest" Header set X-Instance "1" Header set X-Version "${project.version}" RequestHeader set ZRAY-DISABLE 1

<Directory "/var/www/html"> Order allow,deny Allow from all AllowOverride all

`

@davidl-zendhttps://github.com/davidl-zend

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/zendtech/php-zendserver-docker/issues/9#issuecomment-408141393, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AFH5F35J6j1IOXW-e5Kr9xa4VaxvPJy4ks5uKeN0gaJpZM4S84lC.