title: Config Dockerfile for running cronjob
body: <p>I'm new in Docker and I'm facing a problem with my custom Dockerfile which needs some help from you guys. It's working fine until I add some code to run the cronjob in the docker container.</p>
  
  <p>This is my Dockerfile file:</p>
  
  <pre><code>FROM php:7.2-fpm-alpine
  
  COPY cronjobs /etc/crontabs/root
  
  // old commands
  
  ENTRYPOINT ["crond", "-f", "-d", "8"]
  </code></pre>
  
  <p>This is <code>cronjobs</code> file:</p>
  
  <pre><code>* * * * * cd /var/www/html &amp;&amp; php artisan schedule:run &gt;&gt; /dev/null 2&gt;&amp;1
  </code></pre>
  
  <p>This is <code>docker-compose.yml</code> file:</p>
  
  <pre><code>version: '3'
  
  networks:
    laravel:
  
  services:
  
    nginx:
      image: nginx:stable-alpine
      container_name: nginx_ctrade
      ports:
        - "8081:80"
      volumes:
        - ./app:/var/www/html
        - ./config/nginx/default.conf:/etc/nginx/conf.d/default.conf
        - ./config/certs:/etc/nginx/certs
        - ./log/nginx:/var/log/nginx
      depends_on:
        - php
        - mysql  
      networks:
        - laravel
      working_dir: /var/www/html
  
    php:
      build:
        context: ./build
        dockerfile: php.dockerfile
      container_name: php_ctrade
      volumes:
        - ./app:/var/www/html
        - ./config/php/php.ini:/usr/local/etc/php/php.ini
      networks:
        - laravel
  
    mysql:
      image: mysql:latest
      container_name: mysql_ctrade
      tty: true
      volumes:
        - ./data:/var/lib/mysql
        - ./config/mysql/my.cnf:/etc/mysql/my.cnf
      environment:
        - MYSQL_ROOT_PASSWORD=secret
        - MYSQL_USER=admin
        - MYSQL_DATABASE=laravel
        - MYSQL_PASSWORD=secret
      networks:
        - laravel
  
  </code></pre>
  
  <p>I re-build the docker images and run it. The cronjob is working ok but when I access the localhost at <code>localhost:8081</code>. It isn't working anymore. The page show <code>502 Bad Gateway</code>, so I checked the Nginx error log. This is the Nginx error shown me:</p>
  
  <pre><code>2020/04/10 13:33:36 [error] 8#8: *28 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.224.1, server: localhost, request: "GET /trades HTTP/1.1", upstream: "fastcgi://192.168.224.3:9000", host: "localhost:8081", referrer: "http://localhost:8081/home"
  </code></pre>
  
  <p>All the containers are still running after updated.</p>
  
  <pre><code>CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                  NAMES
  a2403ece8509        nginx:stable-alpine   "nginx -g 'daemon of…"   18 seconds ago      Up 17 seconds       0.0.0.0:8081-&gt;80/tcp   nginx_ctrade
  69032097b7e4        ctrade_php            "docker-php-entrypoi…"   19 seconds ago      Up 18 seconds       9000/tcp               php_ctrade
  592b483305d5        mysql:latest          "docker-entrypoint.s…"   3 hours ago         Up 18 seconds       3306/tcp, 33060/tcp    mysql_ctrade
  </code></pre>
  
  <p>Is there someone get this issue before? Any help would be appreciated! Thanks so much!</p>