I believe this is the problem as everything works locally, but not when I deploy via GitHub Actions and pull locally again. I’ve tried using GitHub secrets, but that hasn’t worked either. So bad practice, but I’ve removed env from my Dockerignore, and I’m trying to mount the env volume at runtime.
This is my Docker-compose:
version: '3'
services:
web:
build:
context: .
dockerfile: Dockerfile
image: user/site
volumes:
- ./config/.env:/var/www/html/.env
ports:
- "8080:80"
Dockerfile:
# Use the official PHP image with Apache
FROM php:8.1-apache
# Set the working directory in the container
WORKDIR /var/www/html
# Install dependencies required to run Composer
RUN apt-get update && apt-get install -y \
curl \
libpng-dev \
libjpeg-dev \
libfreetype6-dev \
libzip-dev \
unzip
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
# Copy the Composer files
COPY composer.json composer.lock ./
# Install PHP dependencies
RUN composer install
# Copy application files to the container
COPY . .
# Expose port 80 for the web server (localhost:8080)
EXPOSE 80
# Start Apache
CMD ["apache2-foreground"]
and my Docker-build:
name: Build and Deploy
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Install Docker Compose
run: |
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
- name: Build Docker images
run: |
docker-compose -f docker-compose.yml build
docker-compose -f docker-compose.yml push
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install Docker Compose
run: |
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
- name: Deploy with Docker Compose
run: |
docker-compose -f docker-compose.yml up -d
I tried this and it worked locally when I built and upped the docker-compose, but the variable-dependent features don’t run when I deploy via GitHub Actions and then pull locally.