'Install sdkman in docker image

Getting error while installing SDKMAN! in Ubuntu 16.04 docker image.

FROM ubuntu:16.04
RUN apt-get update
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get -qq -y install curl
RUN curl -s https://get.sdkman.io | bash
RUN chmod a+x "$HOME/.sdkman/bin/sdkman-init.sh"
RUN source "$HOME/.sdkman/bin/sdkman-init.sh"


Solution 1:[1]

make sure you have curl, wget, unzip & zip. With them I am able to install Sdkman successfully. Following is my Docker content

FROM ubuntu:18.04

RUN apt-get update
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get -qq -y install curl wget unzip zip

RUN curl -s "https://get.sdkman.io" | bash
RUN source "$HOME/.sdkman/bin/sdkman-init.sh"

Solution 2:[2]

TL;DR

Install unzip & zip, which means change

RUN apt-get -qq -y install curl

to

RUN apt-get -qq -y install curl unzip zip

or better

RUN apt-get -qq -y install \
    curl \
    unzip \
    zip

Explanation

When you try to build the Dockerfile, you will get

    .....

    Step 5/6 : RUN curl -s https://get.sdkman.io | bash
    ---> Running in 1ce678a59561

    --- SDKMAN LOGO ---

    Now attempting installation...

    Looking for a previous installation of SDKMAN...
    Looking for unzip...
    Not found.
    ======================================================================================================
    Please install unzip on your system using your favourite package manager.

    Restart after installing unzip.
    ======================================================================================================

    Removing intermediate container 1ce678a59561
    ---> 22211eafd50c
    Step 6/6 : RUN source "$HOME/.sdkman/bin/sdkman-init.sh"
    ---> Running in 1c5cb7d79ef0
    /bin/sh: /root/.sdkman/bin/sdkman-init.sh: No such file or directory
    The command '/bin/sh -c source "$HOME/.sdkman/bin/sdkman-init.sh"' returned a non-zero code: 1

What you need to do is written just there. This part:

    ======================================================================================================
    Please install unzip on your system using your favourite package manager.

    Restart after installing unzip.
    ======================================================================================================

When you install unzip, you get the same error with zip. After installing it, everything works fine.

So, read your logs/command output. :-)


*P.S. It would be better if curl -s https://get.sdkman.io | bash exited with non-zero code. This way it fails on the next command. But that is not a thing you can fix ;) *

Solution 3:[3]

It looks like the sdkman install failed. When I ran your code above it complained about missing the unzip and zip packages.

After satisfying the dependencies, you'll also need to mark the init script as executable with:

chmod a+x "$HOME/.sdkman/bin/sdkman-init.sh"

So your Dockerfile should look something like:

FROM ubuntu:16.04
RUN apt-get update
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get -q -y install curl zip unzip
RUN curl -s https://get.sdkman.io | bash
RUN chmod a+x "$HOME/.sdkman/bin/sdkman-init.sh"
RUN source "$HOME/.sdkman/bin/sdkman-init.sh"

P.S: Beaten to the punch!

Solution 4:[4]

FROM ubuntu:16.04
RUN apt-get update
RUN apt-get -qq -y install \
    curl \
    unzip \
    zip
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get -qq -y install curl
RUN curl -s https://get.sdkman.io | bash
RUN chmod a+x "$HOME/.sdkman/bin/sdkman-init.sh"

RUN source "$HOME/.sdkman/bin/sdkman-init.sh"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2
Solution 3 MisterSheep
Solution 4 kesarling He-Him