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"
A multistage build allows you to use multiple images to build a final product. In a multistage build, you have a single Dockerfile, but can define multiple images inside it to help build the final image.
Pull a repository with multiple images By default, docker pull pulls a single image from the registry. A repository can contain multiple images. To pull all images from a repository, provide the -a (or --all-tags ) option when using docker pull .
As Kingsley Uchnor said, you can have multiple Dockerfile , one per directory, which represent something you want to build.
Multiple containers can run simultaneously, each based on the same or different images. Docker is similar to virtual machines in the way it creates multiple instances of an operating system.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With