0

I have a web application (React and Laravel) Dockerized but it doesn't recognize code changes.

docker-compose.yml

services:
  mysql:
    image: mysql:5.7
    container_name: hoopcliq-mysql
    restart: always
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: hoopcliqdb
      MYSQL_USER: laravel
      MYSQL_PASSWORD: secret

  redis:
    image: redis:latest
    container_name: hoopcliq-redis
    restart: always
    ports:
      - "6379:6379"

  backend:
    build:
      context: ./backend
    container_name: hoopcliq-backend
    depends_on:
      - mysql
      - redis
    ports:
      - "8000:8000"
      - "6001:6001"
    volumes:
      - ./backend:/var/www:delegated
      - vendor-data:/var/www/vendor
    environment:
      DB_HOST: mysql
      DB_DATABASE: hoopcliqdb
      DB_USERNAME: laravel
      DB_PASSWORD: secret
      REDIS_HOST: redis

  frontend:
    build:
      context: ./frontend
    container_name: hoopcliq-frontend
    depends_on:
      - backend
    ports:
      - "3000:3000"
    working_dir: /app
    volumes:
      - ./frontend:/app:delegated
      - frontend_node_modules:/app/node_modules

volumes:
  vendor-data:  # Named volume for vendor directory
  frontend_node_modules: # Named volume for frontend node_modules directory

Dockerfile (frontend)

# Use Node.js LTS image
FROM node:22-alpine

# Set working directory
WORKDIR /app

# Copy package files
COPY package.json package-lock.json ./

# Install dependencies
RUN npm install

# Copy the rest of the application
COPY . .

# Expose port 3000 for the React app
EXPOSE 3000

# Start the application
CMD ["npm", "start"]

Dockerfile (backend)

FROM php:8.4-fpm

WORKDIR /var/www

# system deps + PHP extensions
RUN apt-get update && apt-get install -y \
  default-mysql-client redis-tools libpng-dev libonig-dev libxml2-dev zip unzip git curl supervisor \
  && docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd

# pull in composer binary
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# copy app & supervisor config
COPY . /var/www
COPY supervisord.conf /etc/supervisor/conf.d/hoopcliq.conf

# install PHP deps, generate key, optimize autoloader
RUN composer install --optimize-autoloader --no-interaction \
  && php artisan key:generate \
  && composer dump-autoload --optimize

# copy our startup script
COPY entrypoint.sh /usr/local/bin/entrypoint.sh

# Make sure entrypoint.sh is executable
RUN chmod +x /usr/local/bin/entrypoint.sh

# make it the container entrypoint
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

# EXPOSE ports but the entrypoint will exec supervisord
EXPOSE 8000 6001
1
  • You should be able to run e.g. docker compose up -d backend to start the backend service and its dependencies, and then use ordinary non-container tools to develop the frontend application. Would that approach work for you? It would also let you simplify the Docker setup and make it more reproducible. Commented May 6 at 1:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.