My containers should share the same source code folder.
But they should build from different Dockerfiles.
Is it possible to build them with docker-compose and build from different Dockerfiles at a time?
I wish there is a syntax like
build: . -f <<Dockerfile_ABC>
build: . -f <<Dockerfile_CDE>
abc:
build: . -f <<Dockerfile_ABC>
environment:
- PROJECT=abc
command: ruby abc/abc.rb
volumes:
- ./:/working_direcotry
ports:
- 5904:5904
cde:
build: . -f <Dockerfile_CDE>
environment:
- PROJECT=cde
command: ruby cde/cde.rb
volumes:
- ./:/working_direcotry
ports:
- 5902:5902
As Kingsley Uchnor said, you can have multiple Dockerfile , one per directory, which represent something you want to build. I like to have a docker folder which holds each applications and their configuration. Here's an example project folder hierarchy for a web application that has a database.
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.
But since Docker allows only a single ENTRYPOINT (to be precise, only the last ENTRYPOINT in the Dockerfile has an effect), you need to find a way to run multiple processes (the tunnel and the application) with a single command.
Using multi-stage dockerfiles, you can use several base images as well as previous intermediate image layers to build a new image layer.
The following worked for me
abc:
build:
context: .
dockerfile: Dockerfile.one
def:
build:
context: .
dockerfile: Dockerfile.two
Of course you can tweak the context as needed if you have different contexts. I also use this to have separate Dockerfile.production versions to set things up differently for production versions of the app.
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