Compiling Qt5 project in windows docker container - c++

I'm setting up a Docker container with Qt5 5.12.2 and I'm using a microsoft visual studio 15 compiler msvc2015_64 to build my project. However, I get a LNK1112: module machine type 'x64' conflicts with target machine type 'X86' error when building.
My first step is to build the Qt5 project with the same commands that are generated by Qt Creator:
C:\Qt\5.12.2\msvc2015_64\bin\qmake.exe C:\Users\userA\Desktop\Projects\myproj\app.pro -spec win32-msvc "CONFIG+=debug" "CONFIG+=qtquickcompiler" && C:\Qt\Tools\QtCreator\bin\jom.exe qmake_all
C:\Qt\Tools\QtCreator\bin\jom.exe
This produces the machine type conflict error.
I have tried to add the following paths to my %path% env variable:
C:\Windows\System32
C:\Qt\5.12.2\msvc2015_64\bin
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin
Already in my path env variable:
C:\Program Files (x86)\Windows Kits\8.1\bin\x86
C:\Program Files (x86)\Windows Kits\8.1\Windows Perormance Toolkit\
I have also tried to run the .bat files inside Microsoft Visual Studio 14.0:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\vcvarsx86_amd64.bat
Output of running the .bat file:
ERROR: Cannot determine the location of the VS Common Tools folder
I've looked this error up and I think the suggestion was to add the C:\Windows\System32 to the env variable %path%. I tried that but same error.
My Dockerfile:
FROM microsoft/windowsservercore:10.0.14393.1884
LABEL Description="Windows Server Core development environment for Qbs with Qt 5.12.2, Chocolatey and various dependencies for testing Qbs modules and functionality"
# Disable crash dialog for release-mode runtimes
RUN reg add "HKLM\SOFTWARE\Microsoft\Windows\Windows Error Reporting" /v Disabled /t REG_DWORD /d 1 /f
RUN reg add "HKLM\SOFTWARE\Microsoft\Windows\Windows Error Reporting" /v DontShowUI /t REG_DWORD /d 1 /f
# Install Qt5 5.12.2
COPY qtifwsilent.qs C:\\qtifwsilent.qs
RUN powershell -NoProfile -ExecutionPolicy Bypass -Command \
$ErrorActionPreference = 'Stop'; \
$Wc = New-Object System.Net.WebClient ; \
$Wc.DownloadFile('http://download.qt.io/archive/qt/5.12/5.12.2/qt-opensource-windows-x86-5.12.2.exe', 'C:\qt.exe') ; \
Echo 'Downloaded qt-opensource-windows-x86-5.12.2.exe' ; \
$Env:QT_INSTALL_DIR = 'C:\\Qt' ; \
Start-Process C:\qt.exe -ArgumentList '--verbose --script C:/qtifwsilent.qs' -NoNewWindow -Wait ; \
Remove-Item C:\qt.exe -Force ; \
Remove-Item C:\qtifwsilent.qs -Force
ENV QTDIR C:\\Qt\\5.12.2\\msvc2015
ENV QTDIR64 C:\\Qt\\5.12.2\\msvc2015_64
RUN dir "%QTDIR64%" && dir "%QTDIR64%\bin"
# Install choco for psuedo package manager
RUN #powershell -NoProfile -ExecutionPolicy Bypass -Command \
$Env:chocolateyVersion = '0.10.8' ; \
$Env:chocolateyUseWindowsCompression = 'false' ; \
"iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
RUN choco install -y python2 --version 2.7.14 && refreshenv && python --version && pip --version
RUN choco install -y qbs --version 1.9.1 && qbs --version
RUN choco install -y unzip --version 6.0 && unzip -v
RUN choco install -y visualcpp-build-tools --version 14.0.25420.1 && dir "%PROGRAMFILES(X86)%\Microsoft Visual C++ Build Tools"
# RUN choco install -y windows-sdk-10.1
# RUN choco install -y vcredist2008 --version 9.0.30729.6161
# RUN choco install -y vcredist2010
RUN choco install -y zip --version 3.0 && zip -v
# for building the documentation
RUN pip install beautifulsoup4 lxml
My qtifwsilent.qs to setup Qt5 has these components:
widget.deselectAll();
widget.selectComponent("qt.qt5.5122.win32_msvc2015");
widget.selectComponent("qt.qt5.5122.win64_msvc2015_64");
widget.selectComponent("qt.qt5.5122.qtcharts");
widget.selectComponent("qt.qt5.5122.qtdatavis3d");
widget.selectComponent("qt.qt5.5122.qtpurchasing");
widget.selectComponent("qt.qt5.5122.qtvirtualkeyboard");
widget.selectComponent("qt.qt5.5122.qtwebengine");
widget.selectComponent("qt.qt5.5122.qtnetworkauth");
widget.selectComponent("qt.qt5.5122.qtwebglplugin");
widget.selectComponent("qt.qt5.5122.qtscript");
widget.selectComponent("qt.tools.vcredist_msvc2015_x86");
widget.selectComponent("qt.tools.vcredist_msvc2015_x64");
I expect the project to build and generate an exe file.

I solved the problem so I'm just posting this here for future reference.
I had to update the Dockerfile to use a newer version of servercore as well as included required Windows kits. I also had to add several paths to my %path% environment variable as shown below.
FROM mcr.microsoft.com/windows/servercore:ltsc2019
LABEL Description="Windows Server Core development environment for Qbs with Qt 5.12.2, Chocolatey and various dependencies for testing Qbs modules and functionality"
# Disable crash dialog for release-mode runtimes
RUN reg add "HKLM\SOFTWARE\Microsoft\Windows\Windows Error Reporting" /v Disabled /t REG_DWORD /d 1 /f
RUN reg add "HKLM\SOFTWARE\Microsoft\Windows\Windows Error Reporting" /v DontShowUI /t REG_DWORD /d 1 /f
# Install Qt5 5.12.2
COPY qtifwsilent.qs C:\\qtifwsilent.qs
RUN powershell -NoProfile -ExecutionPolicy Bypass -Command \
$ErrorActionPreference = 'Stop'; \
$Wc = New-Object System.Net.WebClient ; \
$Wc.DownloadFile('http://download.qt.io/archive/qt/5.12/5.12.2/qt-opensource-windows-x86-5.12.2.exe', 'C:\qt.exe') ; \
Echo 'Downloaded qt-opensource-windows-x86-5.12.2.exe' ; \
$Env:QT_INSTALL_DIR = 'C:\\Qt' ; \
Start-Process C:\qt.exe -ArgumentList '--verbose --script C:/qtifwsilent.qs' -NoNewWindow -Wait ; \
Remove-Item C:\qt.exe -Force ; \
Remove-Item C:\qtifwsilent.qs -Force
ENV QTDIR C:\\Qt\\5.12.2\\msvc2015
ENV QTDIR64 C:\\Qt\\5.12.2\\msvc2015_64
RUN dir "%QTDIR64%" && dir "%QTDIR64%\bin"
# Install choco for psuedo package manager
RUN #powershell -NoProfile -ExecutionPolicy Bypass -Command \
$Env:chocolateyVersion = '0.10.14' ; \
$Env:chocolateyUseWindowsCompression = 'false' ; \
"iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
RUN choco install -y python2 --version 2.7.14 && refreshenv && python --version && pip --version
RUN choco install -y qbs && qbs --version
RUN choco install -y unzip --version 6.0 && unzip -v
RUN choco install -y vcbuildtools -ia "/Full"
RUN choco install -y zip --version 3.0 && zip -v
RUN choco install -y cmake
RUN choco install -y windows-sdk-10.1
RUN choco install -y vcredist2008 --version 9.0.30729.6161
RUN choco install -y vcredist2010
# for building the documentation
RUN pip install beautifulsoup4 lxml
WORKDIR C:\\Users\\ContainerUser
For the environment path I used:
set path=%path%;"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC";C:\Qt\5.12.2\msvc2015_64\bin;"C:\Program Files (x86)\Windows Kits\10\bin\x64";"C:\Program Files (x86)\Windows Kits\8.1\bin\x64";C:\Qt\Tools\QtCreator\bin;
# Run this command to setup cl.exe
vcvarsall.bat x86_amd64

Related

Redgate SQL Toolbelt components are not installing in Jenkins inbound-agent windows docker image

I am trying to create a custom Docker image using jenkins/inbound-agent:jdk17-windowsservercore-ltsc2019 image. In this custom image, I want to install Redgate SQL Change Automation Powershell tool.
I tried all different ways of installing it, however, this doesn't seems to install at all.
The different ways I tried are:
Using chocolatey RUN choco install sqltoolbelt -y --params "/products:'SQL Change Automation Powershell'") - This step just times out after running for a long time
Downloaded the SCAPowershell exe and tried to install it:
ENV SCA_URI=https://download.redgate.com/checkforupdates/SCAPowerShell/SCAPowerShell_4.5.22306.32404.exe
RUN Invoke-WebRequest -Uri $env:SCA_URI -OutFile C:\SCAPowerShell_4.5.22306.32404.exe; \
Start-Process -FilePath C:\SCAPowerShell_4.5.22306.32404.exe -ArgumentList "--quiet", "--wait", "/IAgreeToTheEula"
- This step doesn't throw any error, but the component is never installed inside C:\Program Files (x86)\Red Gate\ directory where it's supposed to install
Downloaded the SQL Toolbelt exe and tried to install it. This step also doesn't throw any error, but the component is never installed inside C:\Program Files (x86)\Red Gate\ directory where it's supposed to install
Installed powershell 7 and tried to install the SQL Change Automation module using:
RUN Install-Module SqlChangeAutomation -AcceptLicense -force
This also doesn't install the component inside C:\Program Files (x86)\Red Gate directory where it's supposed to install
Please could someone help me so that I can try to get this installed in my docker image.
I'm already installing some of the prerequisites before installing this Regdate SQL Change Automation tool, like VS Tools, SSMS, SQLLocalDB, VS Community, but it still doesn't install.
Thank you
I got it working after putting below in my Dockerfile. Here's my Dockerfile
FROM jenkins/inbound-agent:jdk17-windowsservercore-ltsc2019
SHELL ["powershell.exe", "-ExecutionPolicy", "Bypass", "-Command"]
RUN ["powershell","Set-ExecutionPolicy Bypass -Scope Process -Force;","iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"]
# Install VS Tools
RUN Invoke-WebRequest -Uri https://aka.ms/vs/17/release/vs_buildtools.exe -OutFile C:\vs_buildtools.exe; \
Start-Process -FilePath C:\vs_buildtools.exe -ArgumentList "install", "--installPath", "C:/BuildTools", "--quiet", "--wait", "--add", "Microsoft.VisualStudio.Workload.VCTools", "--add", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64" -Wait -PassThru
# Install 7Zip
RUN choco install 7zip.install -y
# Install SQL Server 2019
ADD https://download.microsoft.com/download/7/c/1/7c14e92e-bdcb-4f89-b7cf-93543e7112d1/SQLServer2019-x64-ENU-Dev.iso C:\\Users\\jenkins\\SQLServer2019-x64-ENU-Dev.iso
RUN 7z.exe x -y -oC:\\Users\\jenkins\\sqlserversetup C:\\Users\\jenkins\\SQLServer2019-x64-ENU-Dev.iso; \
powershell -Command Remove-Item C:\\Users\\jenkins\\SQLServer2019-x64-ENU-Dev.iso; \
C:\\Users\\jenkins\\sqlserversetup\\setup.exe /q /ACTION=Install /INSTANCENAME=MSSQLSERVER /FEATURES=SQLEngine /UPDATEENABLED=0 /SQLSVCACCOUNT='NT AUTHORITY\System' /SQLSYSADMINACCOUNTS='BUILTIN\ADMINISTRATORS' /TCPENABLED=1 /NPENABLED=0 /IACCEPTSQLSERVERLICENSETERMS
# Install Net Framerwork 4.7
RUN choco install -y netfx-4.7-devpack
# Install VS Community
RUN Invoke-WebRequest -Uri https://aka.ms/vs/17/release/vs_Community.exe -OutFile C:\vs_Community.exe; \
Start-Process -FilePath C:\vs_Community.exe -ArgumentList "install", "--installPath", "C:/VS", "--quiet", "--wait", "--norestart", "--add", "Microsoft.VisualStudio.Workload.CoreEditor", "--add", "Microsoft.VisualStudio.Workload.Data" -Wait -PassThru
# Check installation done or not
RUN dir C:/VS
RUN dir C:/BuildTools
# Install MS ODBC Driver for SQL Server
RUN Invoke-WebRequest -Uri https://download.microsoft.com/download/D/5/E/D5EEF288-A277-45C8-855B-8E2CB7E25B96/x64/msodbcsql.msi -OutFile C:\msodbcsql.msi; \
Start-Process msiexec.exe -Wait -ArgumentList '/I C:\msodbcsql.msi /quiet'
# Install MS Command Line Utilities
RUN Invoke-WebRequest -Uri https://download.microsoft.com/download/C/8/8/C88C2E51-8D23-4301-9F4B-64C8E2F163C5/x64/MsSqlCmdLnUtils.msi -OutFile C:\MsSqlCmdLnUtils.msi; \
Start-Process msiexec.exe -Wait -ArgumentList '/I C:\MsSqlCmdLnUtils.msi /quiet'
#Install SSMS
RUN choco install sql-server-management-studio -y
# Install SQL Change Automation
#RUN choco install sqltoolbelt -y --params "/products:'SQL Change Automation, SQL Change Automation Powershell'"
#RUN Install-PackageProvider NuGet -Force; Install-Module PowerShellGet -MinimumVersion 1.6 -Force -AllowClobber
#RUN Install-Module SqlChangeAutomation -Scope CurrentUser -AcceptLicense
RUN Get-PackageProvider NuGet -ForceBootstrap | Out-Null; Import-PackageProvider PowerShellGet; \
Install-Module -Name PowerShellGet -RequiredVersion 2.2.5 -Force; \
Invoke-Command { & "powershell.exe" } -NoNewScope
RUN Install-Module -Name SqlChangeAutomation -Force -AcceptLicense -ErrorAction Stop
RUN Invoke-Command { & "powershell.exe" } -NoNewScope
#RUN Invoke-DatabaseBuild
# Install pwsh
RUN choco install pwsh -y
SHELL ["pwsh", "-Command"]
# Set environment variable for MSBuild
RUN setx /M PATH $($Env:PATH+';C:/BuildTools/MSBuild/Current/bin/;')
# Install aws cli
RUN choco install awscli -y
#Install SQLLocalDB
RUN choco install sqllocaldb -y

How to install brew into a Dockerfile (`brew: not found`)

Rather than necro-post on a two-year old thread, I decided to create a new question.
I want add brew (homebrew) to a Docker container, but I get a brew: not found error.
The suggested solution in that previous article doesn't seem to work. This new Dockerfile...
FROM rust:1.63.0-buster
WORKDIR app
RUN apt-get update && \
apt-get install -y -q --allow-unauthenticated \
git \
sudo
RUN useradd -m -s /bin/zsh linuxbrew && \
usermod -aG sudo linuxbrew && \
mkdir -p /home/linuxbrew/.linuxbrew && \
chown -R linuxbrew: /home/linuxbrew/.linuxbrew
USER linuxbrew
RUN /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
USER root
RUN chown -R $CONTAINER_USER: /home/linuxbrew/.linuxbrew
RUN brew install hello
gives this error... What am I missing? Thanks.
=> ERROR [6/6] RUN brew install hello 0.2s
------
> [6/6] RUN brew install hello:
#9 0.181 /bin/sh: 1: brew: not found
------
executor failed running [/bin/sh -c brew install hello]: exit code: 127
This Dockerfile installs brew in /home/linuxbrew/.linuxbrew/bin/brew. Including that directory in the path (with the ENV command) does the trick.
...
ENV PATH="/home/linuxbrew/.linuxbrew/bin:${PATH}"
RUN brew install hello

Unable to install Tesseract 5.0 version on AWS Lambda

I want to run Tesseract 4.0 or Tesseract 5.0 on my AWS Lambda function. So I have my docker file like so-
FROM public.ecr.aws/lambda/python:3.8
RUN mkdir app
# Copy function code
COPY / ${LAMBDA_TASK_ROOT}/app
# Install the function's dependencies using file requirements.txt
# from your project folder.
COPY requirements.txt .
RUN pip3 install -r requirements.txt --target ${LAMBDA_TASK_ROOT}
RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
RUN yum -y update
RUN yum -y install tesseract
RUN yum install -y poppler-utils
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "app.com.emlAndMsgParser.mail_parser_test.getEmail_from_msg" ]
but when i do DockerBuild-"docker build -t qa-lambda ." on my terminal, it says Tesseract 3.0 version is getting installed. When i deploy this built Docker image to AWS Lambda,it also says Tesseract 3.0 is installed.
But I want Tesseract 4.0 or preferably Tesserct 5.0.
I tried changing the "RUN yum -y install tesseract" in my Dockerfile to "RUN yum -y install tesseract 5.0.0-alpha-320-g8dc3" and "RUN yum -y install tesseract -y" or "RUN yum -y install tesseract*".
But all of them are installing Tesseract 3.0.
Please can anyone tell me where I am going wrong?
I am a bit new to Tesseract, so any help is appreciated..thanks!
Having the same problem, I finally created a Dockerfile myself:
FROM public.ecr.aws/lambda/java:11 q
# Prepare dev tools
RUN yum -y update
RUN yum -y install wget libstdc++ autoconf automake libtool autoconf-archive pkg-config gcc gcc-c++ make libjpeg-devel libpng-devel libtiff-devel zlib-devel
RUN yum group install -y "Development Tools"
# Build leptonica
WORKDIR /opt
RUN wget http://www.leptonica.org/source/leptonica-1.82.0.tar.gz
RUN ls -la
RUN tar -zxvf leptonica-1.82.0.tar.gz
WORKDIR ./leptonica-1.82.0
RUN ./configure
RUN make -j
RUN make install
RUN cd .. && rm leptonica-1.82.0.tar.gz
# Build tesseract
RUN wget https://github.com/tesseract-ocr/tesseract/archive/refs/tags/5.2.0.tar.gz
RUN tar -zxvf 5.2.0.tar.gz
WORKDIR ./tesseract-5.2.0
RUN ./autogen.sh
RUN PKG_CONFIG_PATH=/usr/local/lib/pkgconfig LIBLEPT_HEADERSDIR=/usr/local/include ./configure --with-extra-includes=/usr/local/include --with-extra-libraries=/usr/local/lib
RUN LDFLAGS="-L/usr/local/lib" CFLAGS="-I/usr/local/include" make -j
RUN make install
RUN /sbin/ldconfig
RUN cd .. && rm 5.2.0.tar.gz
# Optional: install language packs
RUN wget https://github.com/tesseract-ocr/tessdata/raw/main/deu.traineddata
RUN wget https://github.com/tesseract-ocr/tessdata/raw/main/eng.traineddata
RUN mv *.traineddata /usr/local/share/tessdata
WORKDIR /root
ENTRYPOINT [ "tesseract", "--version" ]
Hope this helps!

Cross compiler link in Docker container

I have some troubles using a docker container in order to cross compile a program with visual studio 2019.
Here is my docker file
FROM ubuntu:16.04
RUN dpkg-divert --local --rename --add /sbin/initctl
RUN ln -sf /bin/true /sbin/initctl
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get -y upgrade
# install 32 bit libraries required for gnuarm tools from
# https://launchpad.net/gcc-arm-embedded & a few minimalistic tools with ssh server
RUN dpkg --add-architecture i386 && \
apt-get update && \
apt-get -y install \
libc6:i386 libncurses5:i386 libstdc++6:i386 libpython2.7:i386 vim \
make git unzip \
sudo curl less tree openssh-server
# clean cache
RUN apt-get clean
RUN mkdir -p /var/run/sshd
COPY *.tgz /tmp/
RUN cd /tmp && \
tar zxvf gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf_5.3_sub1.0.3.tgz -C /opt && \
tar zxvf Compiler_gcc-linaro-5.3_patch_1.2.2.tgz && \
cd Compiler_gcc-linaro-5.3_patch && \
bash ./install-owa4x-comp-PATCH-1.2.2.sh && \
cd / && \
rm -rf /tmp/*
ENV PATH="${PATH}:/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin"
RUN useradd -G sudo --create-home --shell /bin/bash --user-group myuser
RUN echo "myuser:myuser_pwd" | chpasswd
RUN echo "PATH=$PATH:/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linuxgnueabihf/bin" >> /etc/profile
CMD ["source /etc/profile"]
CMD ["/usr/sbin/sshd", "-D"]
EXPOSE 22
ENV WORKSPACE /home/myuser/workspace
VOLUME ${WORKSPACE}
Here is how a create my image
docker build --tag cc_arm .
myuser#ubuntu:~/Documents/share$ docker run -d -p 5000:22 -v /home/myuser/Documents/share:/home/myuser/workspace cc_arm
But when I open a shell and type
which g++
which gcc
I have nothing. I've also tried to set the path manually
export C="/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc"
export CXX="/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++"
echo 'export CC=/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc' >> ~/.bashrc
echo 'export CXX=/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++' >> ~/.bashrc
But it doesn't work.
I think my environnement is okay because I can cross compile a simple programm using a g++ from the packages (locate in /usr/bin/g++)
sudo apt install -y openssh-server build-essential gdb rsync ninja-build zip
Thanks in advance.
Finally, I've changed my project in Visual Studio 2019 to a CMake project.
I've created a CMake file in the shared volume of my container.
SET(CMAKE_C_COMPILER /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++)
SET(CMAKE_STRIP /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-strip)
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_PROCESSOR arm)
SET(CMAKE_SYSTEM_VERSION 1)
And in Visual Studio 2019, I've changed the launch.vs.json
"configurations": [
{
"type": "cppgdb",
"name": "CMakeProject6 (CMakeProject6\\CMakeProject6)",
"project": "CMakeLists.txt",
"projectTarget": "CMakeProject6 (CMakeProject6\\CMakeProject6)",
"debuggerConfiguration": "gdb",
"args": [],
"env": {},
"remoteMachineName": "10.0.0.1 (username=root, port=22, authentication=Password)",
"deploy": [
{
"sourceMachine": "192.168.72.144 (username=root, port=5000, authentication=Password)", // DOCKER CONTAINER
"targetMachine": "10.0.0.1 (username=root, port=22, authentication=Password)", // REMOTE MACHINE
"deploymentType": "RemoteRemote"
}
]
}

sdkman does not install java in a dockerfile

I have this docker file:
# We are going to star from the jhipster image
FROM jhipster/jhipster
# install as root
USER root
### Setup docker cli (don't need docker daemon) ###
# Install some packages
RUN apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common -y
# Add Dockers official GPG key:
RUN ["/bin/bash", "-c", "set -o pipefail && curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -"]
# Add a stable repository
RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# Setup aws credentials as environment variables
ENV AWS_ACCESS_KEY_ID "change it!"
ENV AWS_SECRET_ACCESS_KEY "change it!"
# noninteractive install for tzdata
ARG DEBIAN_FRONTEND=noninteractive
# set timezone for tzdata
ENV TZ=America/Sao_Paulo
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# Install the latest version of Docker Engine - Community and also aws cli
RUN apt-get update && apt-get install docker-ce docker-ce-cli containerd.io awscli -y
# change back to default user
USER jhipster
# install skd and java version 1.8
RUN curl -s "https://get.sdkman.io" | bash
RUN bash $HOME/.sdkman/bin/sdkman-init.sh
RUN bash -c "sdk install java 8.0.222.j9-adpt"
When I run a command to build an image from this dockerfile it fails on the last step with a message:
/bin/sh: 1: sdk: not found
When I install it on my local machine it runs sdkman (sdk) on bash. But on this script it calls it from sh not bash. How can I make it calls skdman (sdk) from sh? What I actually want to do is install a specific java version through sdkman (sdk). Is there another way to do it?
For sdk command to be available you need to run source sdkman-init.sh.
Here is a working sample with java 11 on centos.
FROM centos:latest
ARG CANDIDATE=java
ARG CANDIDATE_VERSION=11.0.6-open
ENV SDKMAN_DIR=/root/.sdkman
# update the image
RUN yum -y upgrade
# install requirements, install and configure sdkman
# see https://sdkman.io/usage for configuration options
RUN yum -y install curl ca-certificates zip unzip openssl which findutils && \
update-ca-trust && \
curl -s "https://get.sdkman.io" | bash && \
echo "sdkman_auto_answer=true" > $SDKMAN_DIR/etc/config && \
echo "sdkman_auto_selfupdate=false" >> $SDKMAN_DIR/etc/config
# Source sdkman to make the sdk command available and install candidate
RUN bash -c "source $SDKMAN_DIR/bin/sdkman-init.sh && sdk install $CANDIDATE $CANDIDATE_VERSION"
# Add candidate path to $PATH environment variable
ENV JAVA_HOME="$SDKMAN_DIR/candidates/java/current"
ENV PATH="$JAVA_HOME/bin:$PATH"
ENTRYPOINT ["/bin/bash", "-c", "source $SDKMAN_DIR/bin/sdkman-init.sh && \"$#\"", "-s"]
CMD ["sdk", "help"]
The problem is every RUN command in Dockerfile is executed within a new bash environment, so you need to put both of your last two commands under the same line to look like this:
RUN bash $HOME/.sdkman/bin/sdkman-init.sh && bash -c "sdk install java 8.0.222.j9-adpt"