Wednesday, November 3, 2021

[SOLVED] Laravel docker: adsist-docker_app_1 exited with code 1

Issue

im trying to set up a Laravel project.

The setup is:

  • Centos
  • Apache
  • MySql

I have split containers for App, Web, Database

And app container is fail to run :(

This is my docker-compose.yml:

version: '2'
services:

  # The Application
  app:
    build:
      context: ./
      dockerfile: app.dockerfile
    working_dir: /var/www
    volumes:
      - ./:/var/www
    environment:
      - "DB_PORT=3306"
      - "DB_HOST=database"

  # The Web Server
  web:
    build:
      context: ./
      dockerfile: web.dockerfile
    working_dir: /var/www
    volumes_from:
      - app
    ports:
      - 8080:80

  # The Database
  database:
    image: mysql:5.6
    volumes:
      - dbdata:/var/lib/mysql
    environment:
      - "MYSQL_DATABASE=homestead"
      - "MYSQL_USER=homestead"
      - "MYSQL_PASSWORD=secret"
      - "MYSQL_ROOT_PASSWORD=secret"
    ports:
      - "33061:3306"

volumes:
  dbdata:

This is my app.dockerfile

FROM centos:7.5.1804

RUN yum update -y

RUN yum install epel-release http://rpms.remirepo.net/enterprise/remi-release-7.rpm yum-utils -y && \
    yum-config-manager --enable remi-php72 && \
    yum update -y

RUN yum install vim wget curl unzip \
    php php-json php-gd php-mbstring php-pdo php-xml php-mysqlnd -y

RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
    php composer-setup.php --install-dir=/usr/local/bin --filename=composer && \
    rm -rf composer-setup.php

RUN curl -sL https://rpm.nodesource.com/setup_8.x | bash - && \
    yum install nodejs -y

RUN yum clean all

EXPOSE 80

# Keep container active
CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]

And this is my web.dockerfile:

FROM httpd:2.4

COPY httpd.conf /etc/httpd/conf/httpd.conf

When I run docker-compose up shows some messages:

app_1 | AH00526: Syntax error on line 119 of /etc/httpd/conf/httpd.conf: app_1 | DocumentRoot '/var/www/html' is not a directory, or is not readable

adsist-docker_app_1 exited with code 1


Solution

/var/www/html set as apache documentroot is popular in most linux distributions, but this is not the thing in httpd docker image. Additional, even you modify http.conf to use /var/www/html, you still should mount to /var/www/html, not /var/www.

And back to the httpd image, you could see next:

$ docker run -idt httpd:2.4
docker ps
CONTAINER ID    IMAGE       COMMAND              CREATED STATUS  PORTS               NAMES
182c63e24082    httpd:2.4   "httpd-foreground"   3 seconds ago   Up 1 second 80/tcp  clever_bassi
$ docker exec -it clever_bassi /bin/bash
root@182c63e24082:/usr/local/apache2/conf# cat httpd.conf
......
DocumentRoot "/usr/local/apache2/htdocs"
......

So, if you do not change default settings, you should mount your host's files to /usr/local/apache2/htdocs to serve your service.

And more, COPY httpd.conf /etc/httpd/conf/httpd.conf in your Dockerfile is also not correct, it should be COPY httpd.conf /usr/local/apache2/conf/httpd.conf.



Answered By - atline