cli icon indicating copy to clipboard operation
cli copied to clipboard

when using dockerComposeFile prebuilds are ignored

Open sarj21 opened this issue 1 year ago • 2 comments

We have the following devcontainers.json file at .devcontainers/flask/devcontainers.json:

{
	"name": "flask",
	"dockerComposeFile": [
		"../../docker-compose.app.yaml",
		"../docker-compose.app.dev.yaml"
	],
	"service": "flask",
	"workspaceFolder": "/home/jan",
	"features": {},
	"customizations": {
		"vscode": {
			"settings": {
				...
			},
			"extensions": [
				...
			]
		}
	}
}

Running devcontainer up --workspace-folder . --config .devcontainer/flask/devcontainer.json works fine, it builds the image and stands up the docker compose service.

I want to utilize prebuilding with our docker compose stack so I take the resulting built images and push them to our repository. If anyone pulls those images and runs devcontainer up --workspace-folder . --config .devcontainer/flask/devcontainer.json it rebuilds the entire image from scratch

If in the devcontainers.json I use the image field then it doesn't rebuild but there's no good way to use something like VS Code's > Reopen in Container since it doesn't know it part of the docker compose stack.

Does devcontainers support using prebuilt images with docker compose files? Is there somethings special I need to do to get it to recognize the image is fully built or to point directly at the cache?

To me it seems like it seems to be running docker compose build instead of docker compose up when running devcontainers up. If I run docker compose up myself and then attach VS Code it seems to work as intended.

sarj21 avatar Aug 01 '24 17:08 sarj21

I recommend building the image with a separate configuration (this can be just a Dockerfile or a devcontainer.json) and then reference the resulting image in the docker-compose.yml without referencing a Dockerfile. This avoids relying on Docker's cache hits across machines and potentially architectures.

chrmarti avatar Sep 03 '24 12:09 chrmarti

I'd like to up-vote fixing this bug. My devcontainer.json refs my docker-compose.yml, and that defines both an image: and a build:. Using "docker compose up" works as I expect, if the image is available it is pulled/used, else the image is built. But "devcontainer up" always rebuilds the image. That just seems wrong. I think if you want that behaviour there should be an extra flag to enable it, like with "docker compose up --build". But without the extra flag it should do "docker compose up", not "docker compose build".

If you are worried about breaking it for existing stuff, I suppose an extra flag to "not force rebuild" would work. I would then just have to remember to set it to get what I consider the normal behaviour.

stan-quinn avatar Feb 26 '25 19:02 stan-quinn