Build Error: lstat composer.lock: no such file or directory


#1

Running the Docker file found here ( https://documentation.codeship.com/pro/languages-frameworks/php/#codeship-servicesyml) getting the following error “Build Error: lstat composer.lock: no such file or directory”


#2

That Dockerfile mentions both the composer.json file used to specify which dependencies to install, as well as the composer.lock file, which is used to make sure to install the same set of dependencies on different systems (same versions). You can get more information on the lock file at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file

However, if that file is not yet available (because you didn’t install dependencies locally yet), you’d need to create it or modify the Dockerfile.

To create the lockfile modify the Dockerfile and replace COPY composer.json composer.lock ./ with only COPY composer.json ./. The build the Docker image and create the lockfile by running the following commands

docker build --tag my-php-application .
docker run -it --rm -v $(pwd):/app my-php-application composer install

The second command mounts your current directory to the /app directory in the Docker container and then runs composer install to install the dependencies. Because composer install will write the lockfile and you mounted the directory to the Docker container you will end up with the composer.lock file in your local directory.

Once that’s done you can revert the Dockerfile to the version including the lockfile and are ready to go.