Skip to content

Instantly share code, notes, and snippets.

@pebo
Last active June 10, 2023 06:02
Show Gist options
  • Save pebo/ae810238eb2a4e0d27334e0a0f9e5d3d to your computer and use it in GitHub Desktop.
Save pebo/ae810238eb2a4e0d27334e0a0f9e5d3d to your computer and use it in GitHub Desktop.
docker compose with base image
# usage
docker compose up
version: "3"
services:
base:
image: base-image
build:
context: .
dockerfile: ./Dockerfile
target: base
deploy:
replicas: 0
sub-with-build:
build:
context: .
dockerfile: ./Dockerfile
target: sub
command: echo 'sub-with-build' && cat /bar.txt
depends_on:
- base
sub-with-image:
image: base-image
command: echo 'sub-with-image' && cat /bar.txt
depends_on:
- base
FROM alpine as base
RUN echo 'foo' > /foo.txt
RUN echo 'sleeping for 10s' && sleep 10
FROM base-image as sub
RUN echo 'bar' > /bar.txt && cat /foo.txt >> /bar.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment