You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker部署Laravel项目时COPY composer.lock失败求助

Fixing "COPY failed: stat ... composer.lock: no such file or directory" in Laravel Docker Setup

Hey there, let's get this Docker build error sorted out quickly! The error you're seeing happens because Docker can't find the composer.lock file in your project root directory when it tries to copy it into the image. Here's how to fix it:

Step 1: Generate the Missing composer.lock File

Your Laravel project root (~/laravel-app) is missing the composer.lock file, which is required by your Dockerfile's first COPY instruction. To create it:

  • If you already have a Laravel project skeleton (with composer.json), run this command in ~/laravel-app:
    composer install
    
    This will install all dependencies and generate both composer.lock and the vendor directory.
  • If you're starting fresh, create a complete Laravel project first:
    composer create-project laravel/laravel .
    
    This sets up all necessary files including composer.json and composer.lock.

Step 2: Verify Your Working Directory

Make sure you're running the docker-compose up -d command from inside ~/laravel-app. Docker uses your current working directory as the build context—if you run the command from a different folder, it won't be able to access the project files like composer.lock.

If you need a quick fix and don't mind unstable dependency versions, you can modify your Dockerfile to remove the composer.lock from the first COPY line:

# Replace this line:
COPY composer.lock composer.json /var/www/
# With this:
COPY composer.json /var/www/

Then, when the Docker image runs composer install later, it will generate a composer.lock inside the container. But note that this can lead to different dependency versions across builds, so it's not ideal for production.

After completing Step 1 (and Step 2 if needed), re-run docker-compose up -d—your build should succeed now!

内容的提问来源于stack exchange,提问作者psudo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 09:14:19