buys-fran
buys-fran

Reputation: 29

Why does docker-compose build give me no such file or directory error message

I want to setup a laravel dev environment using docker and docker-compose. And I cannot get my Dockerfile to build.

I have followed tutorials without success:

When I use sudo docker exec -it php sh I log into the php instance and I am able to run composer install.

docker-compose.yml

  build:
    context: .
    dockerfile: Dockerfile
  container_name: php
  restart: unless-stopped
  tty: true
  volumes:
    - ./src:/var/www                                                                                                  
  ports:                                                                                                   
    - "9000:9000"                                                                                                 
  networks:                                                                                                   
    - laravel

Dockerfile

FROM php:7.0-fpm-alpine
WORKDIR /var/www
COPY composer.lock composer.json /var/www

Step 3/3 : COPY composer.lock composer.json /var/www/ ERROR: Service 'php' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder015559251/composer.lock: no such file or directory

Here is my directory structure when I terminal into the php instance. enter image description here

Upvotes: 0

Views: 3256

Answers (1)

buys-fran
buys-fran

Reputation: 29

Just in case anybody else lands up over here:

I had this line in my docker file:

COPY composer.lock composer.json /var/www

And it should have been: ''' COPY src/composer.lock src/composer.json . '''

Essentially your copy from path (first two arguments) is relative to the Dockerfile. And the paste to path is relative to the WORKDIR, which was already set to /var/www.

I hope this helps, but please comment if there is anything I need to clarify.

Upvotes: 0

Related Questions