0

I want to use the same Dockerfile for Windows and Linux containers. It uses build arguments top define the base image like:

FROM $SDK_REPO:$SDK_VERSION AS build-env

It also defines a argument called $PLATFORM which is either linux or windows.

Now I want to install a package only when the image is build for linux. I tried to use an if switch like:

RUN if [ $PLATFORM = linux ]; then apt-get update && apt-get install -y <mypackage>; fi

Obviously, this doesn't work on windows because its using bash syntax.

Is it somehow possible to use the same dockerfile both for windows and linux containers and to do an apt-get install only when my platform argument is linux?

David Maze
  • 130,717
  • 29
  • 175
  • 215
Tobias von Falkenhayn
  • 1,355
  • 5
  • 26
  • 59

1 Answers1

0

After some investigation, I found a way to do it by following the examples of this thread: Single script to run in both Windows batch and Linux Bash?

In my case, I use:

RUN :; apt-get update && apt-get install -y

This will execute only on Linux but be skipped on Windows.

Tobias von Falkenhayn
  • 1,355
  • 5
  • 26
  • 59