Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to build docker image by docker-compose.yml

Here is my docker-compose.yml:

version: '2'
services:
web:
  build: .
  context: ./
  dockerfile: Dockerfile
  ports:
    - "8080:8080"
  container_name: demo
  volumes:
    - .:/images

I got an error:

ERROR: The Compose file './docker-compose.yml' is invalid because: Unsupported config option for services.web: 'dockerfile'

So I would like to build the container and also run. I will have a few more containers to build and run. Is it possible by docker-compose?

like image 618
masiboo Avatar asked Oct 31 '25 02:10

masiboo


1 Answers

If I'm not mistaken the issue is after build you have a dot, the dockerfile and context are not correct idented. And I think the bar in the context should not be there.

version: "3.7"
services:
  api:
    image: image-name
    build:
      context: .
      dockerfile: path/to/Dockerfile
    container_name: container-name

I think this resolves the issue you have, but couldn't test it.

like image 61
Alexandre Avatar answered Nov 03 '25 01:11

Alexandre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!