Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine OS type in docker

I want to download an sdk depending on the OS type my docker image is running on. How can I write the below pseudo code in docker script

RUN variable x = getOS()
if [ "$x" = "Darwin" ]; then
     RUN wget -q http://xxx/android-ndk-xxxx-darwin-x86_64.bin
else
     RUN wget -q http://xxx/android-ndk-xxxx-linux-x86_64.bin
like image 797
ir2pid Avatar asked Oct 16 '22 16:10

ir2pid


1 Answers

Use the uname command.

x=$(uname)

On a darwin system, it should output Darwin.

In your dockerfile, the RUN command then could look like this:

RUN [ "$(uname)" = Darwin ] && system=darwin || system=linux; \
    wget -q http://xxx/android-ndk-xxxx-${system}-x86_64.bin

Or like this (in order to support arbitrary systems):

RUN system=$(uname); \
    wget -q http://xxx/android-ndk-xxxx-${system,}-x86_64.bin
like image 188
hnicke Avatar answered Oct 20 '22 17:10

hnicke