0

I have a service running inside docker using nginx and php-fpm. I have been beating my head against the wall to get all of the logs to redirect to stdout. The approach that I took was to use supervisord. Using docker-compose up my-app everything worked as expected; all of the logs are being sent to stdout. However, when I run

docker run -p 81:80 \
       -v $(pwd)/myapp:/var/www/html \
       my-app

I get no output.

Here is my supervisor configuration:

[supervisord]
nodaemon=true
user=root

[program:php-fpm]
command=/usr/sbin/php-fpm7.0 -F

[program:nginx]
command=/usr/sbin/nginx -g "daemon off;"

[program:nginx-log-access]
command=/usr/bin/tail -f /var/log/nginx/access.log
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
autorestart=true

[program:nginx-log-error]
command=/usr/bin/tail -f /var/log/nginx/error.log
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
autorestart=true

[program:php-fpm-log]
command=/usr/bin/tail -f /var/log/php7.0-fpm.log
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
autorestart=true
startsecs=3

[program:laravel-log]
command=/usr/bin/tail -f /var/www/html/storage/logs/laravel.log
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
autorestart=true

and my docker-compose

version: '3'
services:
  my-app: 
    build:
      context: ../../my-app
      dockerfile: docker/Dockerfile
    image: my-app 
    ports:
     - "81:80"
    volumes:
    - ../../my-app:/var/www/html

my base dockerfile

FROM ubuntu

# Update 
RUN apt-get update --fix-missing && apt-get -y upgrade

# Install Python Setup Tools
RUN apt-get install -y python-pip

# Intall Supervisord
RUN easy_install supervisor

# Install NGINX
RUN apt-get -y install nginx

# Install PHP
RUN apt-get -y install php7.0-fpm \
    php7.0-mbstring \
    php7.0-xml \
    php7.0-curl

# Configure PHP-FPM
RUN sed -i 's/;daemonize = .*/daemonize = no/' /etc/php/7.0/fpm/php-fpm.conf && \
    sed -i "/;clear_env = .*/c\clear_env = no" /etc/php/7.0/fpm/pool.d/www.conf && \
    sed -i -e 's/max_execution_time = 30/max_execution_time = 300/g' /etc/php/7.0/fpm/php.ini && \
    sed -i -e 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /etc/php/7.0/fpm/php.ini && \
    sed -i -e 's/post_max_size = 8M/post_max_size = 50M/g' /etc/php/7.0/fpm/php.ini && \
    sed -i -e "s/variables_order = \"GPCS\"/variables_order = \"EGPCS\"/g" /etc/php/7.0/fpm/php.ini && \
    service php7.0-fpm start && \
    service php7.0-fpm stop

COPY supervisor.conf /etc/supervisor/conf.d/supervisor.conf

CMD ["supervisord", "-n", "-c", "/etc/supervisor/conf.d/supervisor.conf"]

and my application dockerfile

FROM mybase

# Configure NGINX
COPY docker/dev2/default.conf /etc/nginx/sites-enabled/default

# Copy application into container
COPY . /var/www/html

RUN touch /var/www/html/storage/logs/laravel.log && \
    chown www-data:www-data /var/www/html/storage/logs/laravel.log && \
    chmod 644 /var/www/html/storage/logs/laravel.log

COPY docker/dev2/supervisor.conf /etc/supervisor/conf.d/supervisor.conf

CMD ["supervisord", "-c", "/etc/supervisor/conf.d/supervisor.conf"]

What is the difference between docker and docker-compose where redirection to stdout is behaving differently? These containers will be deployed in AWS ECS; I haven't tested this yet, but I am fearful that I will not get successful logging in ECS if I am experiencing this behavior with docker. Any thoughts, ideas, or suggestions would be greatly appreciated!

aberg
  • 11
  • 1
  • 5

1 Answers1

0

When you run docker-compose up output from all docker containers is aggregated and displayed in the console as per

https://docs.docker.com/compose/reference/up/

When you simply run docker run the output is not shown and can only be retrieved with docker logs -f $CONTAINERID

You can also "hide" output with docker compose by using -d flag.

When you run your docker containers in ECS, in the task definition, you can choose the logdriver from the list

http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LogConfiguration.html

Hope this helps.

Andrey
  • 548
  • 2
  • 8