Reputation: 4719
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?
Upvotes: 4
Views: 6574
Reputation: 4739
YAML files works on indentation and an indentation error marks the yaml as invalid. Always validate your yaml in appropriate linting tool for e.g. https://www.yamllint.com/
version: '3.7'
services:
web:
image: my-web-service
build:
dockerfile: Dockerfile
context: .
ports:
- '9080:8080'
context value is .
because my Dockerfile and docker-compose.yaml files exists at the same location
Upvotes: 0
Reputation: 142
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.
Upvotes: 6
Reputation: 2845
You need to respect the indentations , here is an example for building Nginx docker image https://github.com/wshihadeh/three_methods_to_share_assets/blob/master/precompile_during_docker_build/docker-compose.yml
version: '3.7'
services:
web:
build:
context: nginx
dockerfile: Dockerfile
command: server
ports:
- 80:80
Upvotes: 0