Reputation: 738
I should start by saying this I am aware that this project structure may not be ideal, but this is what the higher-ups want so I cannot change this.
I have multiple Java projects in one repo which I'd like to containerise into a single container:
- main
- project1
- project2
- Dockerfile
I have no issue with that; my issue is that I need some other code from a (public) GitHub repo to be running in its own container, within my project container.
- main-container
- project1
- project2
- git-repo-container
I can clone the repository and get it into the container with no issue (assuming git
has been installed in a previous RUN
command):
RUN git clone --progress --verbose https://github.com/user/repo.git
Now, I'm completely stumped on how I go about building and running the container specified in the repo's Dockerfile
.
Naturally, I turned to docker-compose
:
version: "3.9"
services:
my-image:
build: .
image: my-image
ports:
- 8080
- 8100
repo-image:
build: .
image: repo-image
ports:
- 8000
I'm new to docker-compose
so this seems a little confusing to me but I am aware I can build images directly from GitHub. I'm just not sure how to specify the repo's Dockerfile
given that I pull the repo in during the build phase (and would like to avoid installing docker in the container to run docker build ...
in that container).
I should add that I cannot just add the repo's source code to this codebase (not my decision) so pulling in the repo during the build phase appears to be my only option.
As a bit of a side question, if permitted, is there a reason why VS code doesn't show the repo folder when I open the project in a dev container?
Upvotes: 4
Views: 10430
Reputation: 31654
Docker supports build from a direct github URL, see this.
docker build [OPTIONS] PATH | URL | -
So, for you, after translate to compose, the correct way is next:
docker-compose.yaml:
version: "3"
services:
my-image:
build: .
image: my-image
ports:
- 8080
- 8100
repo-image:
build: https://github.com/user/repo.git
image: repo-image
ports:
- 8000
Above will build an image based on third-party code.
Upvotes: 4