Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

FireBlade's avatar

Laravel docker in production not responding

First- on the production server ensure that port 80 is not being used and that no docker container is running. On my dev machine, this is the docker-compose-prod.yml file:

version: "3.7"
services:
  app:
    build:
      context: ./
      dockerfile: Dockerfile2
    image: laranetwork
    container_name: laranetwork-app
    restart: unless-stopped
    working_dir: /var/www/
    networks:
      - laranetwork

  db:
    image: mysql/mysql-server:8.0
    container_name: laranetwork-db
    restart: unless-stopped
    tty: true
    environment:
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_USER: ${DB_USERNAME}
      SERVICE_TAGS: dev
      SERVICE_NAME: mysql
    volumes:
      - ./docker-compose/mysql:/etc/mysql/conf.d/
      - mysqldata:/var/lib/mysql
    networks:
      - laranetwork

  nginx:
    image: nginx:1.21-alpine
    container_name: laranetwork-nginx
    restart: unless-stopped
    ports:
      - 80:80
    volumes:
      - ./docker-compose/nginx-prod:/etc/nginx/conf.d/:ro
    depends_on:
      - app
    networks:
    - laranetwork
 
networks:
  laranetwork:
    driver: bridge

# Volumes
volumes:

  mysqldata:

And Dockerfile2


FROM php:8.1-fpm

# Arguments defined in docker-compose.yml
ARG NODE_VERSION=16

# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    curl \
    libpng-dev \
    libonig-dev \
    libxml2-dev \
    zip \
    unzip

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

RUN apt-get update && apt-get install -y \
    libmagickwand-dev --no-install-recommends && rm -rf /var/lib/apt/lists/* \
    && pecl install imagick \
	&& docker-php-ext-enable imagick \
    && curl -sL https://deb.nodesource.com/setup_$NODE_VERSION.x | bash - \
    && apt-get install -y nodejs \
    && npm install -g npm

RUN apt-get update && apt-get install -y ghostscript

RUN sed -i 's/policy domain="coder" rights="none" pattern="PDF"/policy domain="coder" rights="read|write" pattern="PDF"/' /etc/ImageMagick-6/policy.xml

# Copy existing application directory contents to the working directory
COPY . /var/www
 
# Assign permissions of the working directory to the www-data user
RUN chown -R www-data:www-data \
        /var/www/storage \
        /var/www/bootstrap/cache
USER www-data

# Set working directory
WORKDIR /var/www

The nginx config file:


server {
    listen 80;
    listen [::]:80;
    server_tokens off;
    index index.php index.html;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/public;
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass app:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
    location / {
        try_files $uri $uri/ /index.php?$query_string;
        gzip_static on;
    }
}

So CD into the project dir on my dev machine and run

docker context use prod

docker-compose -f ./docker-compose-prod.yml up -d --build

Confirm that all containers are running ( on production machine ). Then run:

docker-compose exec app php artisan migrate

However, I can't view my app on the browser- timeout after a long wait. There are no errors when I check via


docker-compose logs 

Running


docker-compose exec app ls -l

shows that almost all files and folders are owned by root. Kindly advice. This app works fine on my dev machine.

0 likes
7 replies
FireBlade's avatar

Update:


docker-compose exec app ls /var/www

shows only the docker-compose folder ????

FireBlade's avatar

@Sinnbeck I thought that

COPY . /var/www 

would copy the entire laravel folder structure into the working directory so that I don't need to map since the app runs on a remote server. Let me try...

Sinnbeck's avatar

@FireBlade Ah sorry missed that. So you plan to pull from git inside the container? Or rebuild every time you deploy?

FireBlade's avatar

@Sinnbeck Rebuild every time a change is made ...( am still figuring out this framework ...)

Sinnbeck's avatar

@FireBlade Framework = docker? :) Its the same no matter if you use laravel, or some other framework :)

But try rebuilding the php container from scratch perhaps and see if it runs the copy layer as expected.

FireBlade's avatar

Just realized the nginx.conf file was wrongly named nginx-conf . Quite late to retry the other route since I have already moved the Laravel app folders manually to the server...Maybe will retry soon. Never say die !

Please or to participate in this conversation.