Skip to content

Instantly share code, notes, and snippets.

@hlegius hlegius/Dockerfile
Last active Aug 1, 2019

Embed
What would you like to do?
Docker base configuration for Scala projects with Docker (tested against Docker Beta for OS X)

How to run

$ docker-compose build
$ docker-compose run scala sbt compile
$ docker-compose run scala sbt run
$ docker-compose run scala sbt test
$ docker-compose run scala sbt "~ test" # to run continuously
$ docker-compose run scala # to access Docker's Machine
$ docker-compose run scala sbt ~compile # similar to test above. Works with and without quotes

First run information

It may take a while to fetch all dependencies (libs) based on what's inside your|project build.sbt project file. This configuration shares a local .sbt and .ivy2 directories with Docker's Container /root/.sbt and /root/.ivy2 directories. With sharing, sbt will find your dependencies' cache and will not re-download everything again.

This Dockerfile is based on Scala-sbt Dockerfile from Docker Hub

Tips & Tricks

Put both .sbt and .ivy2 directories under your .gitignore file.

To update Scala/SBT to latest version, remember to remove the old image. You can find it $ docker images and remove the base image named hseeberger/scala-sbt using command $ docker rmi <image-hash-id>, then, build again. You can check which is the latest version here Scala-sbt Dockerfile from Docker Hub

version: '2'
services:
scala:
build: .
volumes:
- .:/exampleapp
- ./.ivy2:/root/.ivy2
- ./.sbt:/root/.sbt
FROM hseeberger/scala-sbt
# For a Alpine Linux version, comment above and uncomment below:
# FROM 1science/sbt
RUN mkdir -p /exampleapp
RUN mkdir -p /exampleapp/out
WORKDIR /exampleapp
COPY . /exampleapp
@viniciusd

This comment has been minimized.

Copy link

viniciusd commented Feb 3, 2019

Shouldn't the WORKDIR instruction be after the COPY in the Dockerfile?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.