Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

marsuch's avatar

docker composer.json not find

Hi, I want to say up front that I'm still learning with the docker. And I'm not using dockerfile but docker-compose. At the same time I use dev enviroments within docker.

From my git I downloaded an older laravel project, and with the help of google I built this docker-compose.yml

################################################################################
# SERVICES
################################################################################
services:

  # ------------------------------------------------------------
  # Nginx
  # ------------------------------------------------------------
  nginx:
    image: nginx:stable-alpine
    environment:
      API_HOST: ${DOCKER_API_HOST}
    restart: always
    ports:
      - "80:80"
    volumes:
      - ./:/var/www/html:cached
      - ./.dockerfiles/nginx/templates:/etc/nginx/templates
    depends_on:
      - php
      - mysql
      - adminer
      - mailhog
    networks:
      laravel:
        aliases:
          - nginx

  # ------------------------------------------------------------
  # MySQL Database
  # ------------------------------------------------------------
  mysql:
    image: mariadb:10.6
    restart: always
    ports:
      - "3306:3306"
    environment:
      - MYSQL_ROOT_PASSWORD
      - MYSQL_DATABASE=${DB_DATABASE}
      - MYSQL_USER=${DB_USERNAME}
      - MYSQL_PASSWORD=${DB_PASSWORD}
      - MYSQL_ALLOW_EMPTY_PASSWORD=yes
    volumes:
      - db_data:/var/lib/mysql
    networks:
      laravel:
        aliases:
          - mysql

  # ------------------------------------------------------------
  # Adminer
  # ------------------------------------------------------------
  adminer:
    image: adminer:latest
    restart: always
    environment:
      ADMINER_DEFAULT_SERVER: mysql
      ADMINER_DATABASE: ${DB_DATABASE}
      ADMINER_USER: ${DB_USERNAME}
      ADMINER_PASSWORD: ${DB_PASSWORD}
      ADMINER_DESIGN: ng9
    ports:
      - "8081:8080"
    depends_on:
      - mysql
    networks:
      laravel:
        aliases:
          - adminer

  # ------------------------------------------------------------
  # PHP
  # ------------------------------------------------------------
  php:
    image: git.j-hof.cz:5050/docker/laravel-php:master
    volumes:
      - ./:/var/www/html:cached
    networks:
      laravel:
        aliases:
          - php

  # ------------------------------------------------------------
  # Redis
  # ------------------------------------------------------------
#  redis:
#    image: redis:alpine
#    container_name: redis
#    restart: always
#    ports:
#      - 6379:6379
#    networks:
#      laravel:
#        aliases:
#          - redis

  # ------------------------------------------------------------
  # Composer 2
  # ------------------------------------------------------------
  composer:
    image: composer:2
    volumes:
      - ./:/var/www/html
    working_dir: /var/www/html
    depends_on:
      - php
    user: root
    entrypoint: ['composer', '--ignore-platform-reqs']
    networks:
      laravel:
        aliases:
          - composer

  # ------------------------------------------------------------
  # NPM
  # ------------------------------------------------------------
  npm:
    image: node:13.7
    volumes:
      - ./:/var/www/html
    ports:
      - "3000:3000"
      - "3001:3001"
    working_dir: /var/www/html
    entrypoint: ['npm']
    networks:
      laravel:
        aliases:
          - npm

  # ------------------------------------------------------------
  # Laravel ARTISAN
  # ------------------------------------------------------------
  artisan:
    image: git.j-hof.cz:5050/docker/laravel-php:master
    volumes:
      - ./:/var/www/html:cached
    working_dir: /var/www/html
    entrypoint: ['php', '/var/www/html/artisan']
    depends_on:
      - mysql
      - php
    networks:
      laravel:
        aliases:
          - artisan


  # ------------------------------------------------------------
  # MailHog
  # ------------------------------------------------------------
  mailhog:
    image: mailhog/mailhog:latest
    container_name: mailhog
    ports:
      - "1025:1025"
      - "8025:8025"
    networks:
      laravel:
        aliases:
          - mailhog

################################################################################
# NETWORK
################################################################################
networks:
  laravel:
    driver: bridge
    driver_opts:
      com.docker.network.enable_ipv6: "false"

################################################################################
# VOLUMES
################################################################################
volumes:
  db_data:
    driver: local

Once I run the script everything downloads fine. But as soon as I try to run the display:

docker-compose run --rm composer install

That's how I get the error:

Composer could not find a composer.json file in /var/www/html
To initialize a project, please create a composer.json file. See https://getcomposer.org/basic-usage
ERROR: 1

Can anyone tell me what to do. Or do I need to create a /var/www/html structure in the project directory. And insert composer.json into it

If I create this structure by default in /var/www/html it does not help

0 likes
4 replies
Sinnbeck's avatar

The docker-compose.yml should be in the root of your project next to your composer.json

marsuch's avatar

There I have it, I found a solution on the internet in the form of removing volumes and workdir pointing to /var/www/html... Which I thought was stupid. But I tried it with no result of course.

Sinnbeck's avatar

@marsuch hmm if they are side by side and you tried rebuilding, then I'm not quite sure

docker-compose build 
marsuch's avatar

@Sinnbeck So it's probably something only the docker dev environment has a problem with. If I run it directly under linux everything works as it should

Please or to participate in this conversation.