My microservices project structure is like this:
my-service-one/
- Dockerfile
- ...
my-service-two/
- Dockerfile
- ...
docker-compose.yml
As you can see, each service directory contains a Dockerfile. There is a docker-compose.yml
in the root level.
The docker-compose.yml
:
version: "3"
services:
service-one:
container_name: service-one
build:
dockerfile: ./my-service-one/Dockerfile
ports:
- "8081:8081"
service-two:
container_name: service-two
build:
dockerfile: ./my-service-two/Dockerfile
ports:
- "8082:8082"
Now, I run docker-compose up -d
from the root. I end up with error:
$ docker-compose up -d
ERROR: The Compose file is invalid because:
Service service-one has neither an image nor a build context specified. At least one must be provided.
My question is why does docker-compose think my service-one
doesn’t have a build context specified? Didn’t I specify it already with:
build:
dockerfile: ./my-service-one/Dockerfile
Why this error?
2
Answers
Peovide a context property below both services in build section like that:
YOUR_DIRECTORY is the place where the files for your project are listed.
Most probably YOUR_DIRECTORY is already written i the child .yml files.
You have a couple of main approaches:
Weeeell, because you did not specified the build context.
No, you specified the dockerfile. No the context.
You have to specify the context so that docker knows what to build.
If you want to build with the context of current directory, you would do:
Maybe the context is inside
my-service-two
, I suspect youw antto write:or really just: