Reputation: 5763
Is there any way to build the multiple images by managing two different dockerfiles? In my case I want to keep two dockerfile suppose Dockerfile_app1 Dockerfile_app2 within the build context.
docker build -t <image_name> .
The above will pick the dockerfile named as Dockerfile
docker build -t <image_name> Dockerfile_app1
This is also not working for my case as It's expecting the file name as Dockerfile.
I have tried by docker-compose build also. However it din't work.
app1:
build: Dockerfile_app1
ports:
- "80:80"
app2:
build: Dockerfile_app2
ports:
- "80:80"
Upvotes: 18
Views: 28094
Reputation: 46480
Just use the -f
argument to docker build
to specify the name of the Dockerfile to use:
$ docker build -t <image_name> -f Dockerfile_app1 .
...
Or in Compose you can use the dockerfile
key from version 1.3 onwards:
app1:
build: .
dockerfile: Dockerfile_app1
ports:
- "80:80"
app2:
build: .
dockerfile: Dockerfile_app2
ports:
- "80:80"
Note that the build
key is for the build context, not the name of the Dockerfile (so it looked for a directory called Dockerfile_app1
in your case).
Upvotes: 33