Can coursier work with alpine in a docker?
I tried to use coursier to install bloop in a docker alpine. While the installed bloop seems not working. see details here https://github.com/scalacenter/bloop/issues/1287
## to have a test
docker run -it --rm alpine
## enter docker alpine
apk update && apk add openjdk11-jdk
wget -O /usr/bin/coursier https://git.io/coursier-cli && chmod +x /usr/bin/coursier
coursier install --dir /usr/bin bloop --only-prebuilt=true
bloop server
## it complains
## /usr/bin/bloop: exec: line 4: /usr/bin/.bloop.aux: not found
## But /usr/bin/.bloop.aux is there.
@davidmlw I just commented on https://github.com/scalacenter/bloop/issues/1287.
use coursier bootstrap bloop --standalone -o bloop. Solved
I think that you might need to create a build specifically for musl platforms using the -H:UseMuslC option of GraalVM. You can find out more about it (and sample usage) at these 2 links:
https://jamesward.com/2020/05/07/graalvm-native-image-tips-tricks/ https://github.com/oracle/graal/issues/2146
As a workaround, you can use the alpine-glibc image:
$ docker run -i -t frolvlad/alpine-glibc:alpine-3.12 /bin/ash
$ apk add libstdc++
$ wget https://github.com/coursier/launchers/raw/master/cs-x86_64-pc-linux
$ chmod +x cs-x86_64-pc-linux
$ ./cs-x86_64-pc-linux
./cs-x86_64-pc-linux: /usr/lib/libstdc++.so.6: no version information available (required by ./cs-x86_64-pc-linux)
Coursier 2.0.7
Usage: cs [options] [command] [command-options]
Available commands: bootstrap, channel, complete, fetch, get, install, java, java-home, launch, list, publish, resolve, setup, uninstall, update
Type cs command --help for help on an individual command
The instructions on https://www.scala-lang.org/download/ definitely don't work (at the very least they should warn about alpine, but perhaps there should be a wrapper script that deals with these edges)...:
curl -fL https://github.com/coursier/coursier/releases/latest/download/cs-x86_64-pc-linux.gz | gzip -d > cs && chmod +x cs && ./cs setup
- https://github.com/VirtusLab/coursier-m1/issues/156
curl -fL https://github.com/VirtusLab/coursier-m1/releases/latest/download/cs-aarch64-pc-linux.gz | gzip -d > cs && chmod +x cs && ./cs setup
% docker run --platform linux/amd64 -it alpine
Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
fe07684b16b8: Pull complete
Digest: sha256:8a1f59ffb675680d47db6337b49d22281a139e9d709335b492be023728e11715
Status: Downloaded newer image for alpine:latest
/ # apk add curl gzip;
fetch https://dl-cdn.alpinelinux.org/alpine/v3.22/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.22/community/x86_64/APKINDEX.tar.gz
(1/13) Installing brotli-libs (1.1.0-r2)
(2/13) Installing c-ares (1.34.5-r0)
(3/13) Installing libunistring (1.3-r0)
(4/13) Installing libidn2 (2.3.7-r0)
(5/13) Installing nghttp2-libs (1.65.0-r0)
(6/13) Installing libpsl (0.21.5-r3)
(7/13) Installing zstd-libs (1.5.7-r0)
(8/13) Installing libcurl (8.14.1-r1)
(9/13) Installing curl (8.14.1-r1)
(10/13) Installing ncurses-terminfo-base (6.5_p20250503-r0)
(11/13) Installing libncursesw (6.5_p20250503-r0)
(12/13) Installing less (679-r0)
(13/13) Installing gzip (1.14-r1)
Executing busybox-1.37.0-r18.trigger
OK: 13 MiB in 29 packages
/ # curl -fL https://github.com/coursier/coursier/releases/latest/download/cs-x86_64-pc-linux.gz | gzip -d > cs && chmod +x cs && ./cs setup
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 22.2M 100 22.2M 0 0 10.7M 0 0:00:02 0:00:02 --:--:-- 16.3M
qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory
Picking the static version of cs is more promising:
/ # curl -fL https://github.com/coursier/coursier/releases/download/v2.1.24/cs-x86_64-pc-linux-static.gz | gzip -d > cs && chmod +x cs && ./cs setup
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 21.5M 100 21.5M 0 0 12.7M 0 0:00:01 0:00:01 --:--:-- 19.1M
Checking if a JVM is installed
https://github.com/coursier/jvm-index/raw/master/index.json
100.0% [##########] 2.6 MiB (2.2 MiB / s)
No JVM found, should we try to install one? [Y/n]
Should we update ~/.profile? [Y/n]
Some shell configuration files were updated. It is recommended to close this terminal once the setup command is done, and open a new one for the changes to be taken into account.
Checking if ~/.local/share/coursier/bin is in PATH
Should we add ~/.local/share/coursier/bin to your PATH via ~/.profile? [Y/n]
Checking if the standard Scala applications are installed
Installed ammonite
Installed cs
Installed coursier
Installed scala
Installed scalac
Installed scala-cli
Installed sbt
Installed sbtn
Installed scalafmt
/ # . ~/.profile
/ # apk add bash
(1/2) Installing readline (8.2.13-r1)
(2/2) Installing bash (5.2.37-r0)
Executing bash-5.2.37-r0.post-install
Executing busybox-1.37.0-r18.trigger
OK: 15 MiB in 31 packages
/ # scala
qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory
ok, so something went wrong
/ # which scala
/root/.local/share/coursier/bin/scala
/ # apk add cmd:file
(1/2) Installing libmagic (5.46-r2)
(2/2) Installing file (5.46-r2)
Executing busybox-1.37.0-r18.trigger
OK: 25 MiB in 33 packages
/ # file /root/.local/share/coursier/bin/scala
/root/.local/share/coursier/bin/scala: a /usr/bin/env sh script executable (Zip archive)
note that java works:
/ # java
Usage: java [options] <mainclass> [args...]
(to execute a class)
or java [options] -jar <jarfile> [args...]
(to execute a jar file)
or java [options] -m <module>[/<mainclass>] [args...]
java [options] --module <module>[/<mainclass>] [args...]
(to execute the main class in a module)
or java [options] <sourcefile> [args]
(to execute a single source-file program)
Arguments following the main class, source file, -jar <jarfile>,
-m or --module <module>/<mainclass> are passed as the arguments to
main class.
where options include:
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
--class-path <class search path of directories and zip/jar files>
A : separated list of directories, JAR archives,
and ZIP archives to search for class files.
-p <module path>
--module-path <module path>...
A : separated list of directories, each directory
is a directory of modules.
--upgrade-module-path <module path>...
A : separated list of directories, each directory
is a directory of modules that replace upgradeable
modules in the runtime image
--add-modules <module name>[,<module name>...]
root modules to resolve in addition to the initial module.
<module name> can also be ALL-DEFAULT, ALL-SYSTEM,
ALL-MODULE-PATH.
--list-modules
list observable modules and exit
-d <module name>
--describe-module <module name>
describe a module and exit
--dry-run create VM and load main class but do not execute main method.
The --dry-run option may be useful for validating the
command-line options such as the module system configuration.
--validate-modules
validate all modules and exit
The --validate-modules option may be useful for finding
conflicts and other errors with modules on the module path.
-D<name>=<value>
set a system property
-verbose:[class|module|gc|jni]
enable verbose output
-version print product version to the error stream and exit
--version print product version to the output stream and exit
-showversion print product version to the error stream and continue
--show-version
print product version to the output stream and continue
--show-module-resolution
show module resolution output during startup
-? -h -help
print this help message to the error stream
--help print this help message to the output stream
-X print help on extra options to the error stream
--help-extra print help on extra options to the output stream
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions with specified granularity
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions with specified granularity
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:jdwp
see also -agentlib:jdwp=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
HiDPI scaled images are automatically supported and used
if available. The unscaled image filename, e.g. image.ext,
should always be passed as the argument to the -splash option.
The most appropriate scaled image provided will be picked up
automatically.
See the SplashScreen API documentation for more information
@argument files
one or more argument files containing options
-disable-@files
prevent further argument file expansion
--enable-preview
allow classes to depend on preview features of this release
To specify an argument for a long option, you can use --<name>=<value> or
--<name> <value>.
/ # sh -x /root/.local/share/coursier/bin/scala
+ exec /root/.cache/coursier/arc/https/github.com/scala/scala3/releases/download/3.7.1/scala3-3.7.1-x86_64-pc-linux.tar.gz/scala3-3.7.1-x86_64-pc-linux/bin/scala
qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory
/ # file /root/.cache/coursier/arc/https/github.com/scala/scala3/releases/download/3.7.1/scala3-3.7.1-x86_64-pc-linux.tar.gz/scala3-3.7.1-x86_64-pc-linux/bin/scala
/root/.cache/coursier/arc/https/github.com/scala/scala3/releases/download/3.7.1/scala3-3.7.1-x86_64-pc-linux.tar.gz/scala3-3.7.1-x86_64-pc-linux/bin/scala: Bourne-Again shell script, ASCII text executable
/ # bash -x /root/.cache/coursier/arc/https/github.com/scala/scala3/releases/download/3.7.1/scala3-3.7.1-x86_64-pc-linux.tar.gz/scala3-3.7.1-x86_64-pc-linux/bin/scala
+ '[' -z '' ']'
+ PRG=/root/.cache/coursier/arc/https/github.com/scala/scala3/releases/download/3.7.1/scala3-3.7.1-x86_64-pc-linux.tar.gz/scala3-3.7.1-x86_64-pc-linux/bin/scala
+ '[' -h /root/.cache/coursier/arc/https/github.com/scala/scala3/releases/download/3.7.1/scala3-3.7.1-x86_64-pc-linux.tar.gz/scala3-3.7.1-x86_64-pc-linux/bin/scala ']'
++ pwd
+ saveddir=/
++ dirname /root/.cache/coursier/arc/https/github.com/scala/scala3/releases/download/3.7.1/scala3-3.7.1-x86_64-pc-linux.tar.gz/scala3-3.7.1-x86_64-pc-linux/bin/scala
+ PROG_HOME=/root/.cache/coursier/arc/https/github.com/scala/scala3/releases/download/3.7.1/scala3-3.7.1-x86_64-pc-linux.tar.gz/scala3-3.7.1-x86_64-pc-linux/bin/..
++ cd /root/.cache/coursier/arc/https/github.com/scala/scala3/releases/download/3.7.1/scala3-3.7.1-x86_64-pc-linux.tar.gz/scala3-3.7.1-x86_64-pc-linux/bin/..
++ pwd
+ PROG_HOME=/root/.cache/coursier/arc/https/github.com/scala/scala3/releases/download/3.7.1/scala3-3.7.1-x86_64-pc-linux.tar.gz/scala3-3.7.1-x86_64-pc-linux
+ cd /
+ source /root/.cache/coursier/arc/https/github.com/scala/scala3/releases/download/3.7.1/scala3-3.7.1-x86_64-pc-linux.tar.gz/scala3-3.7.1-x86_64-pc-linux/libexec/common-shared
+++ stty -g
++ saved_stty=500:5:bf:8a3b:3:1c:7f:15:4:0:1:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0
++ [[ ! -n 0 ]]
++ scala_exit_status=127
++ trap onExit INT TERM EXIT
++ unset cygwin mingw msys darwin
++ command -v tput
++ case "`uname`" in
+++ uname
++ unset CYGPATHCMD
++ [[ -n '' ]]
++ [[ -n '' ]]
++ [[ -n '' ]]
++ '[' -z /root/.cache/coursier/arc/https/github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.27%252B6/OpenJDK11U-jdk_x64_alpine-linux_hotspot_11.0.27_6.tar.gz/jdk-11.0.27+6 ']'
++ '[' -z '' ']'
++ '[' -n /root/.cache/coursier/arc/https/github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.27%252B6/OpenJDK11U-jdk_x64_alpine-linux_hotspot_11.0.27_6.tar.gz/jdk-11.0.27+6 ']'
++ '[' -x /root/.cache/coursier/arc/https/github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.27%252B6/OpenJDK11U-jdk_x64_alpine-linux_hotspot_11.0.27_6.tar.gz/jdk-11.0.27+6/jre/sh/java ']'
++ JAVACMD=/root/.cache/coursier/arc/https/github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.27%252B6/OpenJDK11U-jdk_x64_alpine-linux_hotspot_11.0.27_6.tar.gz/jdk-11.0.27+6/bin/java
++ '[' '!' -x /root/.cache/coursier/arc/https/github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.27%252B6/OpenJDK11U-jdk_x64_alpine-linux_hotspot_11.0.27_6.tar.gz/jdk-11.0.27+6/bin/java ']'
++ '[' -z /root/.cache/coursier/arc/https/github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.27%252B6/OpenJDK11U-jdk_x64_alpine-linux_hotspot_11.0.27_6.tar.gz/jdk-11.0.27+6 ']'
++ CLASSPATH_SUFFIX=
++ PSEP=:
++ PROG_HOME_URI=file:///root/.cache/coursier/arc/https/github.com/scala/scala3/releases/download/3.7.1/scala3-3.7.1-x86_64-pc-linux.tar.gz/scala3-3.7.1-x86_64-pc-linux
++ '[' -n '' ']'
++ [[ -n '' ]]
++ [[ -n '' ]]
++ declare -a scala_args
+ source /root/.cache/coursier/arc/https/github.com/scala/scala3/releases/download/3.7.1/scala3-3.7.1-x86_64-pc-linux.tar.gz/scala3-3.7.1-x86_64-pc-linux/libexec/cli-common-platform
++ SCALA_CLI_CMD_BASH=("\"$PROG_HOME/libexec/scala-cli\"")
+ SCALA_VERSION=
+ IFS=
+ read -r line
+ [[ version:=3.7.1 == version:=* ]]
+ SCALA_VERSION=3.7.1
+ break
+ '[' -z 3.7.1 ']'
+ MVN_REPOSITORY=file:///root/.cache/coursier/arc/https/github.com/scala/scala3/releases/download/3.7.1/scala3-3.7.1-x86_64-pc-linux.tar.gz/scala3-3.7.1-x86_64-pc-linux/maven2
+ [[ 0 -gt 0 ]]
+ '[' -z '' -o -n '' ']'
+ export MSYSTEM= PWD=
+ MSYSTEM=
+ PWD=
+ eval '"/root/.cache/coursier/arc/https/github.com/scala/scala3/releases/download/3.7.1/scala3-3.7.1-x86_64-pc-linux.tar.gz/scala3-3.7.1-x86_64-pc-linux/libexec/scala-cli"' '--prog-name scala' --skip-cli-updates '--cli-default-scala-version "3.7.1"' '-r "file:///root/.cache/coursier/arc/https/github.com/scala/scala3/releases/download/3.7.1/scala3-3.7.1-x86_64-pc-linux.tar.gz/scala3-3.7.1-x86_64-pc-linux/maven2"'
++ /root/.cache/coursier/arc/https/github.com/scala/scala3/releases/download/3.7.1/scala3-3.7.1-x86_64-pc-linux.tar.gz/scala3-3.7.1-x86_64-pc-linux/libexec/scala-cli --prog-name scala --skip-cli-updates --cli-default-scala-version 3.7.1 -r file:///root/.cache/coursier/arc/https/github.com/scala/scala3/releases/download/3.7.1/scala3-3.7.1-x86_64-pc-linux.tar.gz/scala3-3.7.1-x86_64-pc-linux/maven2
qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory
+ scala_exit_status=255
+ onExit
+ [[ 500:5:bf:8a3b:3:1c:7f:15:4:0:1:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0 != '' ]]
+ restoreSttySettings
+ stty 500:5:bf:8a3b:3:1c:7f:15:4:0:1:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0
+ saved_stty=
+ exit 255
+ onExit
+ [[ '' != '' ]]
+ exit 255
/ # file /root/.cache/coursier/arc/https/github.com/scala/scala3/releases/download/3.7.1/scala3-3.7.1-x86_64-pc-linux.tar.gz/scala3-3.7.1-x86_64-pc-linux/libexec/scala-cli
/root/.cache/coursier/arc/https/github.com/scala/scala3/releases/download/3.7.1/scala3-3.7.1-x86_64-pc-linux.tar.gz/scala3-3.7.1-x86_64-pc-linux/libexec/scala-cli: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=27bffa21a3fef5f6c245c16be139fc663bb81ae9, for GNU/Linux 3.2.0, with debug_info, not stripped
/ # ls -l /root/.cache/coursier/arc/https/github.com/scala/scala3/releases/download/3.7.1/scala3-3.7.1-x86_64-pc-linux.tar.gz/scala3-3.7.1-x86_64-pc-linux/libexec/scala-cli
-rwxr-xr-x 1 root root 129115608 Jun 2 12:21 /root/.cache/coursier/arc/https/github.com/scala/scala3/releases/download/3.7.1/scala3-3.7.1-x86_64-pc-linux.tar.gz/scala3-3.7.1-x86_64-pc-linux/libexec/scala-cli
Note that it is possible to get scala to run locally in this environment:
/ # curl -L https://github.com/scala/scala3/releases/download/3.7.1/scala3-3.7.1.tar.gz -O
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 138M 100 138M 0 0 53.3M 0 0:00:02 0:00:02 --:--:-- 72.6M
/ # tar xzf scala3-3.7.1.tar.gz
/ # ./scala3-3.7.1/bin/scala
Welcome to Scala 3.7.1 (11.0.27, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala>
Offhand, it seems like it should be possible to test for the various supported libcs and failing that to download packages that contain jars/jar wrappers and run them instead of running binaries that won't work.