I'm currently trying to dockerise a Laravel application, I've managed to create my Dockerfile and docker-compose.yml with the dependencies I need. However, I am struggling to get php-fpm to kick in that will show my application.
Dockerfile
# Set master image
FROM php:8.0-fpm-alpine
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/html/
# Set working directory
WORKDIR /var/www/html
# Install Additional dependencies
RUN apk update && apk add --no-cache \
build-base shadow vim curl \
php8 \
php8-fpm \
php8-common \
php8-pdo \
php8-pdo_mysql \
php8-mysqli \
php8-mbstring \
php8-xml \
php8-openssl \
php8-json \
php8-phar \
php8-zip \
php8-gd \
php8-dom \
php8-session \
php8-zlib \
nodejs \
npm
# Add and Enable PHP-PDO Extenstions
RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-enable pdo_mysql
# Install PHP Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Remove Cache
RUN rm -rf /var/cache/apk/*
# Add UID '1000' to www-data
RUN usermod -u 1000 www-data
# Copy existing application directory permissions
COPY --chown=www-data:www-data . /var/www/html
# Change current user to www
USER www-data
# Install app dependencies
COPY package.json /var/www/html/
RUN npm install
RUN npm run dev
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
docker-compose.yml
version: '3'
services:
#Laravel App
app:
build:
context: .
dockerfile: Dockerfile
image: heychazza/joinservers.com
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www/html
expose:
- "9000:80"
volumes:
- ./:/var/www/html
networks:
- mynet
#Nginx Service
nginx:
image: nginx:alpine
container_name: nginx
restart: unless-stopped
tty: true
ports:
- "8080:80"
volumes:
- ./:/var/www/html
- ./deployment/nginx/conf.d/:/etc/nginx/conf.d/
#- ./nginx/ssl/:/etc/nginx/ssl/
depends_on:
- app
networks:
- mynet
#MySQL Service
db:
image: mariadb:latest
container_name: db
restart: unless-stopped
tty: true
ports:
- "33060:3306"
environment:
MYSQL_DATABASE: laraveldb
MYSQL_USER: laravel
MYSQL_PASSWORD: laravelpassworddb
MYSQL_ROOT_PASSWORD: rootpasswordmysql
MYSQL_ROOT_HOST: '%'
volumes:
- mysqldata:/var/lib/mysql/
networks:
- mynet
#Docker Networks
networks:
mynet:
driver: bridge
#Volumes
volumes:
mysqldata:
driver: local
What am I doing? I'm running Docker from a MacBook, and are looking to deploy this onto a production Debian machine.
I'm still new to docker, so apologies if I've missed anything out.