Install sdkman in docker image - docker

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"

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"

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 ;) *

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!

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"

docker pull kubile/ubuntu-sdkman:23.04
You can try this image.

This Dockerfile seems to work with versions current as of February 2023:
FROM ubuntu:22.04
RUN apt-get update && apt-get install -y curl zip unzip
RUN curl -s "https://get.sdkman.io" | bash
# this SHELL command is needed to allow using source
SHELL ["/bin/bash", "-c"]
# seems you need to put 'sdk install...'' lines in same RUN command as 'source...'.
RUN source "/root/.sdkman/bin/sdkman-init.sh" \
&& sdk install java 19.0.2-tem \
&& sdk install sbt 1.8.2 \
&& sdk install scala 2.13.10

Related

CD command is not working inside a docker container in ubuntu box :18.04(vagrant) [duplicate]

the command :
docker build -t nginx-ubuntu .
whith the Dockerfile below :
FROM ubuntu:12.10
RUN apt-get update
RUN apt-get -y install libpcre3 libssl-dev
RUN apt-get -y install libpcre3-dev
RUN apt-get -y install wget zip gcc
RUN wget http://nginx.org/download/nginx-1.4.1.tar.gz
RUN gunzip nginx-1.4.1.tar.gz
RUN tar -xf nginx-1.4.1.tar
RUN wget --no-check-certificate https://github.com/max-l/nginx_accept_language_module/archive/master.zip
RUN unzip master
RUN cd nginx-1.4.1
RUN ./configure --add-module=../nginx_accept_language_module-master --with-http_ssl_module --with-pcre=/lib/x86_64-linux-gnu --with-openssl=/usr/lib/x86_64-linux-gnu
Fails at the last line (./configure ...)
If I remove the last line and run a bash in the container, and
execute the last line manually, it works.
I would expect that whatever command runs successfully within a container should work
when the command is appended in the Dockerfile (prefixed by RUN)
am I missing something ?
The pwd is not persistent across RUN commands. You need to cd and configure within the same RUN.
This Dockerfile works fine:
FROM ubuntu:12.10
RUN apt-get update
RUN apt-get -y install libpcre3 libssl-dev
RUN apt-get -y install libpcre3-dev
RUN apt-get -y install wget zip gcc
RUN wget http://nginx.org/download/nginx-1.4.1.tar.gz
RUN gunzip nginx-1.4.1.tar.gz
RUN tar -xf nginx-1.4.1.tar
RUN wget --no-check-certificate https://github.com/max-l/nginx_accept_language_module/archive/master.zip
RUN unzip master
RUN cd nginx-1.4.1 && ./configure --add-module=../nginx_accept_language_module-master --with-http_ssl_module --with-pcre=/lib/x86_64-linux-gnu --with-openssl=/usr/lib/x86_64-linux-gnu
As an alternative to #creak's answer, you can change the default working directory in a Dockerfile with the WORKDIR command:
FROM ubuntu:12.10
# Run update & install together so that the docker cache doesn't
# contain an out-of-date APT cache (leading to 404's when installing
# packages)
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install libpcre3 libssl-dev libpcre3-dev wget zip gcc
ADD http://nginx.org/download/nginx-1.4.1.tar.gz nginx-1.4.1.tar.gz
RUN tar -zxf nginx-1.4.1.tar.gz
RUN wget --no-check-certificate https://github.com/max-l/nginx_accept_language_module/archive/master.zip
RUN unzip master
WORKDIR nginx-1.4.1
RUN ./configure --add-module=../nginx_accept_language_module-master --with-http_ssl_module --with-pcre=/lib/x86_64-linux-gnu --with-openssl=/usr/lib/x86_64-linux-gnu
This also affects the default directory when you use docker run (overridden by the -w switch).
When I called wget or tar with RUN I needed to specify a path, it looks like ADD is the correct approach if you want to use WORKDIR as it's path instead. So either of the below resolved my issue.
RUN
RUN wget http://nginx.org/download/nginx-1.4.1.tar.gz -P ~/directory
RUN tar -zxf ~/directory/nginx-1.4.1.tar.gz -C ~/directory
or
ADD
WORKDIR ~/directory
ADD http://nginx.org/download/nginx-1.4.1.tar.gz nginx-1.4.1.tar.gz
RUN tar -zxf nginx-1.4.1.tar.gz
The second approach prevented me from needing to install wget in the container.
Another way of doing this using the \ operator to start a new line and proceed with an additional command
Example
RUN cd /Desktop \
cd Work \
pwd

Permission restriction to do go get command on default user jenkins:jenkins on jenkins pod

I have a docker container that uses a debian image, and inside it, I need to run some **Go get commands **, using the user jenkins:jenkins, because it is the user jenkins use when running a build, but this user by itself don't have permission to do that(mkdir and creating files).
Tried to install sudo on image and run "sudo go get" on jenkins, but it doesn't work because of the env variables.
The dockerfile image I'm using is this one:
FROM debian:latest
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y gnupg2
RUN apt-get install sudo
RUN DEBIAN_FRONTEND="noninteractive" apt install -y apt-transport-https ca-certificates software-properties-common curl git jq wget unzip
RUN curl -s https://storage.googleapis.com/golang/go1.15.6.linux-amd64.tar.gz| tar -v -C /usr/local -xz
ENV PATH=$PATH:/usr/local/go/bin
RUN export PATH=$PATH:/usr/local/go/bin
Before trying to execute the sudo operations, I enter echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers just to make sure that the password won't be needed
Since I'm going to use this image in jenkins later on, I need a solution that I could implement in a "non interactive" way, preferably configuring it directly in the dockerfile.
Thanks!!
Found the solution:
Just like the comments said, the sudo go was not the solution, the solution was to provide the user jenkins:jenkins the permission to do so.
In dockerfile, I've created the user jenkins:jenkins, installed sudo package, and turned the user jenkins into sudo. Pointed the changes with "<-----":
FROM debian:latest
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y gnupg2
RUN apt-get install sudo <-----
RUN addgroup --gid 6002 jenkins <-----
RUN useradd -u 6002 -g jenkins -s /bin/sh jenkins <-----
RUN usermod -aG sudo jenkins <-----
RUN DEBIAN_FRONTEND="noninteractive" apt install -y apt-transport-https ca-certificates software-properties-common curl git jq wget unzip
RUN curl -s https://storage.googleapis.com/golang/go1.15.6.linux-amd64.tar.gz| tar -v -C /usr/local -xz
RUN export PATH=$PATH:/usr/local/go/bin
...
Doing that, in jenkins I was able to run in the Gopath, with the user that jenkins use(jenkins:jenkins), the command: sh "sudo chown -R jenkins:jenkins ./*"
So the sudo go get wasn't needed .

Install kotlin in ubuntu image getting error

I am getting an error while installing kotlin in ubuntu 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 apt-get install -y unzip
RUN apt-get install -y zip
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"
RUN sdk install kotlin
Getting error
Step 10/35 : RUN sdk install kotlin
---> Running in 9282af532681
/bin/sh: sdk: command not found
ERROR: Service 'myproject' failed to build: The command '/bin/sh -c sdk install kotlin' returned a non-zero code: 127
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 apt-get install -y unzip
RUN apt-get install -y zip
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" && sdk install kotlin
Each RUN have their own "session". So RUN sdk install kotlin will not know about previous source command.
Multiple RUN is not optimal: each RUN will create a layer.
Looks like you want to create docker image with Kotlin JVM. Then you need standard openjdk:8-jdk (Or what version you want) and then just put there your jar file.

Supervisor is not starting up

I am following cloudera cdh4 installation guide.
My base file
FROM ubuntu:precise
RUN apt-get update -y
#RUN apt-get install -y curl
RUN apt-get install -y software-properties-common python-software-properties
RUN add-apt-repository ppa:webupd8team/java
RUN apt-get update -y
RUN echo debconf shared/accepted-oracle-license-v1-1 select true | \
debconf-set-selections
RUN apt-get install -y oracle-java7-installer
#Checking java version
RUN java -version
My hadoop installation file
java_ubuntu is the image build from my base file.
FROM java_ubuntu:latest
RUN apt-get update -y
RUN apt-get install -y curl
RUN curl http://archive.cloudera.com/cdh4/one-click-install/precise/amd64/cdh4-repository_1.0_all.deb > cdh4-repository_1.0_all.deb
RUN dpkg -i cdh4-repository_1.0_all.deb
RUN curl -s http://archive.cloudera.com/cdh4/ubuntu/precise/amd64/cdh/archive.key | apt-key add -
RUN apt-get update -y
RUN apt-get install -y hadoop-0.20-conf-pseudo
#Check for /etc/hadoop/conf.pseudo.mrl to verfiy hadoop packages
RUN echo "dhis"
RUN dpkg -L hadoop-0.20-conf-pseudo
Supervisor part
hadoop_ubuntu is the image build from my hadoop installation docker file
FROM hadoop_ubuntu:latest
USER hdfs
RUN hdfs namenode -format
USER root
RUN apt-get install -y supervisor
RUN echo "[supervisord] nodameon=true [program=namenode] command=/etc/init.d/hadoop-hdfs-namenode -D" > /etc/supervisorconf.d
CMD ["/usr/bin/supervisord"]
Program is successfully build. But namenode is not starting up? How to use supervisor?
You have your config in /etc/supervisorconf.d and I don't believe that's the right location.
It should be /etc/supervisor/conf.d/supervisord.conf instead.
Also it's easier to maintain if you make a file locally and then use the COPY instruction to put it in the image.
Then as someone mentioned you can connect to the container after it's running (docker exec -it <container id> /bin/bash) and then run supervisorctl to see what's running and what might be wrong.
Perhaps you need line breaks in your supervisor.conf. Try hand crafting one and COPY it into your dockerfile for testing.
Docker and supervisord

Docker command fails during build, but succeeds while executed within running container

the command :
docker build -t nginx-ubuntu .
whith the Dockerfile below :
FROM ubuntu:12.10
RUN apt-get update
RUN apt-get -y install libpcre3 libssl-dev
RUN apt-get -y install libpcre3-dev
RUN apt-get -y install wget zip gcc
RUN wget http://nginx.org/download/nginx-1.4.1.tar.gz
RUN gunzip nginx-1.4.1.tar.gz
RUN tar -xf nginx-1.4.1.tar
RUN wget --no-check-certificate https://github.com/max-l/nginx_accept_language_module/archive/master.zip
RUN unzip master
RUN cd nginx-1.4.1
RUN ./configure --add-module=../nginx_accept_language_module-master --with-http_ssl_module --with-pcre=/lib/x86_64-linux-gnu --with-openssl=/usr/lib/x86_64-linux-gnu
Fails at the last line (./configure ...)
If I remove the last line and run a bash in the container, and
execute the last line manually, it works.
I would expect that whatever command runs successfully within a container should work
when the command is appended in the Dockerfile (prefixed by RUN)
am I missing something ?
The pwd is not persistent across RUN commands. You need to cd and configure within the same RUN.
This Dockerfile works fine:
FROM ubuntu:12.10
RUN apt-get update
RUN apt-get -y install libpcre3 libssl-dev
RUN apt-get -y install libpcre3-dev
RUN apt-get -y install wget zip gcc
RUN wget http://nginx.org/download/nginx-1.4.1.tar.gz
RUN gunzip nginx-1.4.1.tar.gz
RUN tar -xf nginx-1.4.1.tar
RUN wget --no-check-certificate https://github.com/max-l/nginx_accept_language_module/archive/master.zip
RUN unzip master
RUN cd nginx-1.4.1 && ./configure --add-module=../nginx_accept_language_module-master --with-http_ssl_module --with-pcre=/lib/x86_64-linux-gnu --with-openssl=/usr/lib/x86_64-linux-gnu
As an alternative to #creak's answer, you can change the default working directory in a Dockerfile with the WORKDIR command:
FROM ubuntu:12.10
# Run update & install together so that the docker cache doesn't
# contain an out-of-date APT cache (leading to 404's when installing
# packages)
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install libpcre3 libssl-dev libpcre3-dev wget zip gcc
ADD http://nginx.org/download/nginx-1.4.1.tar.gz nginx-1.4.1.tar.gz
RUN tar -zxf nginx-1.4.1.tar.gz
RUN wget --no-check-certificate https://github.com/max-l/nginx_accept_language_module/archive/master.zip
RUN unzip master
WORKDIR nginx-1.4.1
RUN ./configure --add-module=../nginx_accept_language_module-master --with-http_ssl_module --with-pcre=/lib/x86_64-linux-gnu --with-openssl=/usr/lib/x86_64-linux-gnu
This also affects the default directory when you use docker run (overridden by the -w switch).
When I called wget or tar with RUN I needed to specify a path, it looks like ADD is the correct approach if you want to use WORKDIR as it's path instead. So either of the below resolved my issue.
RUN
RUN wget http://nginx.org/download/nginx-1.4.1.tar.gz -P ~/directory
RUN tar -zxf ~/directory/nginx-1.4.1.tar.gz -C ~/directory
or
ADD
WORKDIR ~/directory
ADD http://nginx.org/download/nginx-1.4.1.tar.gz nginx-1.4.1.tar.gz
RUN tar -zxf nginx-1.4.1.tar.gz
The second approach prevented me from needing to install wget in the container.
Another way of doing this using the \ operator to start a new line and proceed with an additional command
Example
RUN cd /Desktop \
cd Work \
pwd

Resources