Monday, March 7, 2022

[FIXED] Laravel's the composer.lock file is not updated on docker/ docker-compose

Issue

I am working on a Laravel project. I am using docker-compose/ docker as my development environment.

This is my docker-compose.yml file.

version: '3'
services:
  apache:
    container_name: myaneat_apache
    image: webdevops/apache:ubuntu-16.04
    environment:
      WEB_DOCUMENT_ROOT: /var/www/public
      WEB_ALIAS_DOMAIN: myan.localhost
      WEB_PHP_SOCKET: php-fpm:9000
    volumes: # Only shared dirs to apache (to be served)
      - ./public:/var/www/public:cached
      - ./storage:/var/www/storage:cached
    networks:
      - myaneat-network
    ports:
      - "80:80"
      - "443:443"
  php-fpm:
    container_name: myaneat_php
    image: jguyomard/laravel-php:7.3
    volumes:
      - ./:/var/www/
      - ./ci:/var/www/ci:cached
      - ./vendor:/var/www/vendor:delegated
      - ./storage:/var/www/storage:delegated
      - ./node_modules:/var/www/node_modules:cached
      - ~/.ssh:/root/.ssh:cached
      - ./composer.json:/var/www/composer.json
      - ./composer.json:/var/www/composer.lock
      - ~/.composer/cache:/root/.composer/cache:delegated
    networks:
      - myaneat-network
  db:
    container_name: myaneat_db
    image: mariadb:10.2
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: myan
      MYSQL_USER: myan
      MYSQL_PASSWORD: secret
    volumes:
      - myaneat-data:/var/lib/mysql
    networks:
      - myaneat-network
    ports:
      - "33060:3306"
  elasticsearch:
    container_name: myaneat_es
    image: docker.elastic.co/elasticsearch/elasticsearch:6.5.1
    restart: always
    volumes:
      - es-data:/usr/share/elasticsearch/data
    networks:
      - myaneat-network
    ports:
      - "9200:9200"
  kibana:
    image: docker.elastic.co/kibana/kibana:6.5.1
    container_name: myaneat_kibana
    environment:
      - ./kibana.yml:/usr/share/kibana/config/kibana.yml
    ports:
      - "5601:5601"
    networks:
      - myaneat-network
networks:
  myaneat-network:
    driver: "bridge"
volumes:
  myaneat-data:
    driver: "local"
  es-data:
    driver: "local"

I am installing a new package running the following command.

docker-compose exec php-fpm composer require calebporzio/sushi

But only the composer.json is updated but not composer.lock. Also, the package is not downloaded into the vendor folder either. I was working before. Just out of the blue, this happens.

I tried the followings.

docker-compose exec php-fpm composer clearcache
docker-compose exec php-fpm composer clear-cache
docker-compose exec php-fpm composer dump-autoload
docker-compose exec php-fpm composer update --lock

What is the possible root cause? How can I fix it?


Solution

You may try run update specific to the lock:

docker-compose exec php-fpm composer update --lock

This flag is documented here

As for the updating of .lock file, you may find info about it here, You're interesting in the last clause.

Running composer update will:

  1. Check composer.json

  2. Determine the latest versions to install based on your version specs

  3. Install the latest versions

  4. Update composer.lock to reflect the latest versions installed



Answered By - Elad

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.