If anyone is looking for a solution: You would need to first execute
COPY . .
to copy the whole app source (including the missing composer.json) before executing composer install and other php commands.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I recently started learning Docker and I got the basic concepts. I am now trying to build an image for my Laravel project. I would appreciate some help, since I don't really understand some things. My Dockerfile
FROM php:7.4-fpm
ARG user
ARG uid
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
WORKDIR /var/www
RUN npm install tailwindcss
USER $user
And my docker-compose.yml
version: '3'
services:
app:
container_name: expenses_app
build:
args:
user: expenses_user
uid: 1000
context: ./
dockerfile: Dockerfile
image: expenses-app
restart: unless-stopped
working_dir: /var/www
volumes:
- ./:/var/www
networks:
- expenses_network
- db_network
depends_on:
- db
- nodejs
db:
image: mysql:5.7
container_name: expenses_db
restart: unless-stopped
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_USER: ${DB_USERNAME}
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- mysql-volume:/var/lib/mysql
networks:
- db_network
nginx:
image: nginx:alpine
container_name: expenses_nginx
restart: unless-stopped
ports:
- 8000:80
volumes:
- ./:/var/www
- ./config/docker-compose/nginx:/etc/nginx/conf.d
networks:
- expenses_network
nodejs:
image: node:14-alpine
container_name: expenses_nodejs
restart: unless-stopped
volumes:
- ./:/var/www
networks:
- expenses_network
volumes:
mysql-volume:
networks:
db_network:
expenses_network:
driver: bridge
My idea is to add all needed commands that setup the project in the Dockerfile (composer install, npm install, php artisan migrate etc.), but for whatever reason if I add composer install I get - composer.json not found. If I hae an npm install command (in my case tailwind), I get - npm is not installed.
I don't really understand what should I put in the docker-compose and what in the Dockerfile. My understanding is that in the compose file I need to describe what services I want to use and in the Dockerfile I can execute commands (simplifying it of course). But if that's the case, why don't I have composer.json since I'm mounting my project dir? Why don't I have npm since I am adding the node:14-alpine image in the compose file?
Sorry for the wall of text and thanks to whoever reads this.
Please or to participate in this conversation.