0

I am new in Docker so please do not blame me :)

Is there a way to create two different Dockerfiles inherits from one? Example, we have to have 2 environment: develop and production. Theirs base is the same:

FROM gcc
# it's just an example which shows the same base packets for both environment
RUN apt install lib-boost

For "develop" I have to install some utilities like gdb, valgrind etc. For "production" I have to build an application. It thought to use "multi stage builds", but it runs steps in Dockerfile consistently. How I should do if I do not want to build an application in "develop"?

The first build the base image:

build -t base_image .

And then for each Dockerfile use it?

# for develop
FROM base_image
RUN apt install gdb
# for prod
FROM base_image
RUN make
Mike
  • 860
  • 14
  • 24
  • Possible duplicate of [Dockerfile if else condition with external arguments](https://stackoverflow.com/questions/43654656/dockerfile-if-else-condition-with-external-arguments) – leopal Apr 01 '19 at 14:23
  • Your own suggestion will work just fine .. – F.Madsen Apr 01 '19 at 15:20

1 Answers1

0

Here is an example I'm currently using.

Base image Dockerfile:

FROM python:3.6-slim as base

RUN apt update
RUN apt install --no-install-recommends -y git-core build-essential \
 && apt autoclean
# ...

Prod image Dockerfile:

FROM your-registry/base:0.0.0 as prod

# your code
# ...

Hope, it'll be helpful for you.

Leonid Usachov
  • 331
  • 3
  • 7