r/scala•
YurianG

Why Scala does not have an official docker image

I'm getting started with Scala, and really surprise me that a language like Scala does not have an official Docker image on docker hub, and I just wondering... why? Is an organization political/decision or any architecture problem?

EDIT: Thanks for all the responses, as I said I am just getting started and I'm just looking the available tooling, so you helped me a lot :)

Posted Nov 18, 2020, 6:57 PM UTC · edited

916
BalmungSan•

What exactly do you expect on an official docker image of Scala to have?

  • Something for running your app?
  • Something for building and publishing your app (CI/CD)?
  • Something for developing your app?
13
XamEseerts•

I would like to echo and expand upon this. In general I see four use-cases which would require images. Let me first list all of them and then collect the things each of them would need to contain.

  • (a) Local development with a container
  • (b) Cloud development with container
  • (c) Continuous integration pipeline
  • (d) Execution of the application in a container environment (e.g. Kubernetes)

Now before we get started listing the requirements for each image there is one thing all of them need which is some version of Java (JRE only for d, JDK for a, b, c). And here you already have tons of alternatives to choose from. But let's get to the specific images now.

(a) For this you would additionally require your build tool of choice and possibly the Scala version of your choice installed. I say possible because e.g. SBT will take care of this for you so you only need SBT. Additionally depending on your IDE you may or may not require some additional tools installed that let eh IDE help do it's thing (e.g. code highlighting, linting, ...). And what one should also not discard is that you may want Docker to run in your Docker image when your tests utilize the awesome Testcontainers library (https://www.testcontainers.org/).

(b) Equivalent to (a) in terms of requirements.

(c) This one is almost equivalent to (a) with the exception of the IDE specific tools. These can be removed here.

(d) Finally for this one you only need some version of JRE. One thing to note here is that when using SBT to build your application you can utilize the plugin sbt-native-packager (https://sbt-native-packager.readthedocs.io/en/stable/formats/docker.html) to build an image with your application in it for you. I find this incredibly convenient personally as otherwise you would have to define a lot of what I consider to be messy things yourself. I.e. you would need to copy the JAR files your build generated, copy them to a destination in your image and finally configure the entrypoint of the image to be your JAR to be executed. One implication of this however is that (c) again requires Docker (so Docker-in/on-Docker needs to be enabled).

In conclusion I think one can see that different use-cases require different images and even within these use-cases there are many options to be chosen, like the Java version, the build tool and whether or not one wants to use Docker-in/on-Docker. Therefore I think it's not super useful to have some official image which will always fall short for lot's of combinations.

Just for the curious here is an image I once created for running in a CI pipeline (outdated by now):

FROM ubuntu:18.04

# install and setup docker
RUN apt-get update

RUN apt-get install -y \
  apt-transport-https \
  ca-certificates \
  curl \
  gnupg-agent \
  software-properties-common

RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -

RUN add-apt-repository \
  "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) \
  stable"

RUN apt-get update

RUN apt-get install -y docker-ce docker-ce-cli containerd.io

VOLUME /var/lib/docker

ENTRYPOINT ["dockerd"]

# install jdk
RUN apt-get install -y openjdk-8-jdk openjdk-8-demo openjdk-8-doc \
  openjdk-8-jre-headless openjdk-8-source

# install and set up sbt
RUN echo "deb https://dl.bintray.com/sbt/debian /" | tee -a /etc/apt/sources.list.d/sbt.list
RUN apt-key adv --keyserver hkps://keyserver.ubuntu.com:443 --recv 2EE0EA64E40A89B84B2DF73499E82A75642AC823
RUN apt-get update
RUN apt-get install -y sbt

WORKDIR /root

RUN mkdir project && \
  echo 'scalaVersion := "2.12.9"' > build.sbt && \
  echo 'sbt.version=1.3.3' > project/build.properties && \
  echo 'case object Temp' > Temp.scala && \
  sbt compile && \
  rm -r project && rm build.sbt && rm Temp.scala && rm -r target
3
n3ziniuka5•

If you need to build Scala code with sbt, commit sbt-launcher to source control with your project and just use the official openjdk image. In CI, simply use that sbt-launcher as a substitute for sbt. It will download sbt for you so you don't need to have it bundled in an image. Just cache sbt/coursier folders so that CI doesn't have to download them every time.

13
kag0•

Docker is typically for deployment. You don't need anything scala-specific to deploy scala code, so java images work just fine.

You can see, for example, that the default image for the mill docker contrib module uses a java image. Nothing scala specific is added to the build aside from the compiled scala code.

9
Plippe•

Hey,

Not 100% sure why there isn't an official Scala image, but it could be linked to the lack of "official" build tool. Sbt seems to be winning, but isn't official.

I would recommend using a multi build docker image. The first would contain sbt or your built tool of choice. There could be an official image for some. Then use the official openjre to run your packaged application.

Not sure if that helps.

6
YurianGOP•

Oh really? I didn't know about that, SBT looks official for me, thanks for the info! It was helpful

3
MasGui•

Which build systems do you regularly use?

71% sbt
39% Maven
18% Gradle
 3% Pants
 2% Ant
 2% Bazel
 3% Other
 4% None

https://www.jetbrains.com/lp/devecosystem-2019/scala/

10
kag0•

Here are the 2020 numbers

78% sbt
31% maven
19% gradle
 3% ant
 2% mill
 2% bloop
 1% bazel
 1% pants
5
Plippe•

I had to double check, but yes sbt isn't official, but the most used.

There is a talk where Martin Odersky states that he is unsure if sbt was the right approche. I don't believe he recommends another solution, but mostly states that things could be better.

5
dtechnology•

You use openjdk's images for running.

For building look to your CI solution. E.g. circleci/openjdk has sbt, maven and gradle so you can use it to build Scala.

3
Philluminati•

You should turn your app into a jar file (I recommend native-packager or sbt-assembly) and then create a docker image which combines that file with the appropriate jdk. There's no need for any scala specific tools.

3
rdrgvedovato•

You mean for developing, or running Scala code?

2
fhenrir777•

For developing Scala, you don't need docker images and for deployment you only need java so the java images work fine.

2
n1gr3d0•

For developing Scala, you don't need docker images

... unless you use CI.

1
ko_gir•

I created Scala package and published Docker Hub before. How about use it If you like. https://hub.docker.com/repository/docker/kkdk/scala-package

2
[deleted]•

[deleted]

1
[deleted]•

[deleted]

-7
12345Qwerty543•

Openjdk..?

3