0

I'm not a docker expert and I've been searching for an answer to this as it seems like it should be pretty simple -- specifically as a multi-stage build. But if so, it's still not clear to me how I pull off what I'm trying to do within the multi-stage build framework.

original Dockerfile:

FROM python:3.8.5

RUN mkdir /src
WORKDIR /src

RUN apt-get update && apt-get install -y --no-install-recommends \
    git \

COPY api/requirements.txt /src/

RUN pip install pip
RUN pip install -r requirements.txt

COPY . /src/

Additional commands that I'd like effectively inserted after the two RUN pip install lines:

COPY api/requirements-dev.txt /src/
RUN pip install -r requirements-dev.txt

Ideally the second couple of lines would (with whatever FROM ... AS statements might be needed) be in Dockerfile-dev, and then I could just build from Dockerfile-dev to capture whatever changes might be in Dockerfile and tack on my dev dependencies.

Obviously I could just copy the original Dockerfile, add the extra lines, call the result Dockerfile-dev, and build from that. However I'm trying to corral all of the dev dependencies into their own files that explicitly inherit the "prod" files as much as possible, as with docker-compose.yml-like inheritance/overrides. That lets me leave the "prod" code untouched and avoid e.g. conflicts when I merge it in, and makes it clear via additional files what stuff is being added to make my dev environment.

J.T.
  • 41
  • 6
  • see https://stackoverflow.com/a/54245466/564226 – JeffRSon Jun 19 '21 at 21:30
  • Interesting. Not quite what I was thinking, though. Your linked solutions revolve around "if X is present, do Y, otherwise default to Z", which is slightly different than "when I run X command use the core dockerfile, when I run Y command use that same file plus these additional commands". It does seem like the answer is not something simple I'm missing, but rather "it's just easier to maintain two slightly different Dockerfiles". – J.T. Jun 19 '21 at 22:28
  • The "built-in" way would probably be to derive a new Dockerfile.dev "FROM" your runtime Dockerfile. You may choose Dockerfile.dev from command line. – JeffRSon Jun 20 '21 at 09:24

0 Answers0