Reputation: 1410
I have a few containers that are expected to run together. Do I need to create a tiny github repository for each (seems wasteful and inconvenient), or can I use the same github repository as a source for an automated build of multiple containers?
Upvotes: 3
Views: 1250
Reputation: 3555
As per my comment, I needed to set up "automated builds for multiple containers". Unlike the original poster, my use case involved containers that did not need to be used together, but instead were meant to be used independently of each other.
The solution I settled on was to set up subdirectories for each container in the project, and then set up automated builds on Dockerhub to track each subdirectory's Dockerfile with a different tag. So, my git repo (hosted on GitHub) contains something like this:
$ tree containers/
containers/
|-- Makefile
|-- R-3.2.3
| |-- Dockerfile
| `-- install.R
|-- README.md
|-- base
| `-- Dockerfile
|-- bedtools-2.26.0
| `-- Dockerfile
|-- bwa-0.7.17
| `-- Dockerfile
And my Dockerhub account tracks the entire repo and builds containers such as
username/project:R-3.2.3
username/project:bedtools-2.26.0
username/project:bwa-0.7.17
Caveats:
all containers are tracked on the master
branch of the repo, so any change to that branch triggers rebuilds for all containers
the container are built in a random order, so if you have a hierarchy of containers (e.g. custom base layer with intermediary layers) then there is a good chance that changes will not successfully propagate through the whole chain of images and will require triggering manual rebuilds from the Dockerhub website.
Also worth noting that Dockerhub is extremely slow to build, so if you need to push out changes quickly this might not be a viable method.
Upvotes: 2
Reputation: 78021
If the containers are expected to be run together then use docker compose to build and run them. The Docker file associated with each container can then be kept in a sub directory.
├── docker-compose.yml
├── one
│ └── Dockerfile
└── two
└── Dockerfile
web1:
build: one
ports:
- 8080
web2:
build: two
ports:
- 8080
Upvotes: 4
Reputation: 1329572
You can use the same repo and different branches, in order to isolate the history of commits for each container.
Each one can be composed of a Dockerfile, and possibly other resources that the Dockerfile needs to COPY or ADD to the built image.
Since Git 2.5, you can clone that repo and checkout its branches in different folders. See "Multiple working directories with Git?".
Upvotes: 0