How do you organize the Dockerfiles belonging to a project when you have one Dockerfile for the database, one for the application server, and so on? Do you create some sort of hierachy in the source? A big enterprise project can't consist of only one Dockerfile?
相关问题
- Docker task in Azure devops won't accept "$(pw
- Unable to run mariadb when mount volume
- Unspecified error (0x80004005) while running a Doc
- What would prevent code running in a Docker contai
- How to reload apache in php-apache docker containe
In Intellij, I simple changed the name of the docker files to *.Dockerfile, and associated the file type *.Dockerfile to docker syntax.
When working on a project that requires the use of multiple dockerfiles, simply create each dockerfile in a separate directory. For instance,
app/ db/
Each of the above directories will contain their dockerfile. When an application is being built, docker will search all directories and build all dockerfiles.
Add an abstraction layer, for example a YAML file like in this project https://github.com/larytet/dockerfile-generator which looks like
centos7: base: centos:centos7 packager: rpm install: - $build_essential_centos - rpm-build run: - $get_release env: - $environment_vars
A short Python script/make can generate all Dockerfiles from the configuration file
I just create a directory containing a Dockerfile for each component. Example:
When building the containers just give the directory name and Docker will select the correct Dockerfile.
Autho Note
This answer is out of date. Fig not longer exists and has been replaced by Docker compose
Use
docker-compose
and multipleDockerfile
in separate directoriesAs 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.docker-compose.yml
example:docker-compose
command line usage example:In case you need files from previous folders when building your Dockerfile
You can still use the above solution and place your
Dockerfile
in a directory such asdocker/web/Dockerfile
, all you need is to set the buildcontext
in yourdocker-compose.yml
like this:This way, you'll be able to have things like this:
and a
./docker/web/Dockerfile
like this:Here are some quick commands from tldr docker-compose. Make sure you refer to official documentation for more details.
In newer versions(>=1.8.0) of docker, you can do this
A big save.
EDIT: update versions per raksja's comment