所以我有一个问题,似乎无法解决,也找不到解决方案..
我正在使用 React、Sass 和 Laravel 与 docker 制作一个项目,而 docker 不会在线为我的 Laravel 提供服务。它会无限加载,我不知道该怎么办了。
这是我的目录树,我知道它已经磨损,但它可以工作:)
my-project/
├── backend/
│ └── (Laravel files here)
├── frontend/
│ └── (React files here)
├── docker/
│ ├── backend/
│ └── Dockerfile
│ ├── frontend/
│ └── Dockerfile
└── docker-compose.yml
这是我的 docker-compose.yml 文件:
version: '3.8'
services:
backend:
build:
context: ../ # Root of the project
dockerfile: docker/backend/Dockerfile # Path to the Dockerfile
image: lerenlerentool-backend
container_name: lerenlerentool_backend
restart: unless-stopped
working_dir: /var/www
entrypoint: php artisan serve --host=0.0.0.0
volumes:
- ../backend:/var/www # Maps the backend folder into the container
- ./backend/php-local.ini:/usr/local/etc/php/conf.d/local.ini
ports:
- "8000:8000"
networks:
- app-network
environment:
- APP_ENV=local
- APP_DEBUG=true
- APP_KEY=base64:ertrdSfHv01dD/4R6N6acsRQW+hLn3MTNmk84ypaW4I=
- DB_HOST=127.0.0.1
- DB_PORT=3306
- DB_DATABASE=lerenlerentool
- DB_USERNAME=test
- DB_PASSWORD=1234
depends_on:
- db
frontend:
build:
context: ../
dockerfile: docker/frontend/Dockerfile
image: lerenlerentool-frontend
container_name: lerenlerentool_frontend
restart: unless-stopped
ports:
- "3000:80"
volumes:
- ../frontend:/app
- /app/node_modules
networks:
- app-network
db:
image: mysql:8.0
container_name: lerenlerentool_db
restart: unless-stopped
environment:
MYSQL_DATABASE: lerenlerentool
MYSQL_USER: test
MYSQL_PASSWORD: 1234
MYSQL_ROOT_PASSWORD: 1234
volumes:
- dbdata:/var/lib/mysql
ports:
- "3306:3306"
networks:
- app-network
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: lerenlerentool_phpmyadmin
restart: unless-stopped
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: 1234
ports:
- "8080:80"
networks:
- app-network
networks:
app-network:
driver: bridge
volumes:
dbdata:
这是我的 dockerfile:
# Use a PHP image with FPM support
FROM php:8.2-fpm
# Install necessary PHP extensions
RUN apt-get update && apt-get install -y libpng-dev libjpeg-dev libfreetype6-dev zip git unzip
# Install Composer (for Laravel dependency management)
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
# Set the working directory to where the Laravel project is
WORKDIR /var/www/backend
RUN apt-get update && apt-get install -y \
libpng-dev libjpeg-dev libfreetype6-dev \
libonig-dev libzip-dev zip unzip git curl \
&& docker-php-ext-install pdo pdo_mysql bcmath mbstring
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql
# Copy the Laravel project files into the container
COPY backend /var/www/backend
# Install Laravel dependencies via Composer
RUN composer install --optimize-autoloader --no-dev
# Install Node.js and npm (if necessary for any assets)
RUN curl -sL https://deb.nodesource.com/setup_22.x | bash - \
&& apt-get install -y nodejs
# Run Laravel migrations or other setup commands if needed
CMD php artisan serve --host=0.0.0.0 --port=8000
# Expose the correct port (if needed for API)
EXPOSE 8000
我尝试用这个编辑我的dockerfile:
CMD php artisan serve --host=0.0.0.0 --port=8000
我用这个撰写:
entrypoint: php artisan serve --host=0.0.0.0
但我仍然需要进入我的 laravel 项目所在的文件夹,并手动将服务命令输入到该文件夹的 cmd 中,laravel 才能工作。