I am trying to run Laravel 8 (with the database!) in Google Cloud. Deployment is done via Cloud Run with GitHub CI Trigger
What I have done so far: I created all necessary Docker files for building the Docker image and container like the Dockerfile and docker-composer.yml in my apps doc root. Because my app needs a backend and a database, I created an nginx.conf-file and an int_db.sql file, to seed the database.
Dockerfile
FROM php:7.4-fpm
# Arguments defined in docker-compose.yml
ARG user=hannes
ARG uid=1002
# 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 the latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Create system user to run Composer and Artisan Commands
#RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN useradd -u 1002 -G www-data,root -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
# Set working directory
WORKDIR /var/www
USER $user
docker-compose.yml
version: "3.7"
services:
app:
build:
args:
user: hannes
uid: 1002
context: ./
dockerfile: Dockerfile
image: feedbackapp
ports:
- 8080
environment:
# /run/docs/reference/container-contract
PORT: ${PORT:-8080}
K_SERVICE: feedbackapp
K_REVISION: 0
K_CONFIGURATION: feedbackapp
container_name: feedbackapp-container
restart: unless-stopped
working_dir: /var/www/
volumes:
- ./:/var/www
networks:
- feedbackapp
db:
image: mysql:5.7
container_name: feedbackapp-db
restart: unless-stopped
environment:
MYSQL_DATABASE: homestead
MYSQL_ROOT_PASSWORD: homestead
MYSQL_PASSWORD: secret
MYSQL_USER: homestead
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- ./docker-compose/mysql:/docker-entrypoint-initdb.d
networks:
- feedbackapp
nginx:
image: nginx:alpine
container_name: feedbackapp-nginx
restart: unless-stopped
ports:
- 8000:80
volumes:
- ./:/var/www
- ./docker-compose/nginx:/etc/nginx/conf.d/
networks:
- feedbackapp
networks:
feedbackapp:
driver: bridge
feedbackapp.conf
server {
listen 80;
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;
}
}
In my local Docker environment, the Laravel 8 app gets successfully built and is working well, if i request the app via http://localhost:8000/. So I created a Cloud Run Service in Google Cloud with a CI trigger of my GitHub Repo. So every time I push my branch, my Cloud Run Service is triggered and builds my app. The build is finished successfully in Cloud Build.
Problem: if an open the apps link, I get a 503 Service Unavailable error Web
What the log tells me: Log
Any help is much appreciated. Stay safe.