Home > Software engineering >  docker-compose up load build definition error
docker-compose up load build definition error

Time:08-16

I am developing a docker-compose.yml file that looks like so:

version: '3.9'
services:
 web-app: 
   build: ./my-frontend-app.Dockerfile
   ports:
     - "4200:4200"

When I run docker-compose up, I get the following error:

failed to solve with frontend dockerfile.v0: failed to read dockerfile: error from sender: walk /Users/daniel/My_Projects/my-frontend-app/my-frontend-app.Dockerfile: not a directory ERROR: Service 'web-app' failed to build : Build failed

So it failed to build because it cannot locate the directory my Dockerfile is in?

CodePudding user response:

If you use Compose build: with just a string, that string is interpreted as a directory name, and the Dockerfile is assumed to be in a file named exactly Dockerfile in that directory. There is an extended form of build: that lets you specify a dockerfile: within the build context.

version: '3.8'
services:
 web-app: 
   build:
     context: .
     dockerfile: my-frontend-app.Dockerfile

(If you can use all default options – you can use the default dockerfile: Dockerfile and do not need args: or any other special build-time options – I tend to prefer the short build: ./directory-name/ syntax, but it won't work in your case when you have multiple Dockerfiles.)

  • Related