Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cookbook for docker #215

Merged
merged 2 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/scala-docker/HelloDocker.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// File was generated from based on docs/cookbooks/scala-docker.md, do not edit manually!

object HelloDocker extends App {
println("Hello from Docker")
}
56 changes: 56 additions & 0 deletions examples/scala-docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!--
File was generated from based on docs/cookbooks/scala-docker.md, do not edit manually!
-->


# Package Scala application as a docker image

ScalaCLI can create an executable application and package it into a docker image.

Here is a simple piece of code that will be executed in the docker container.

```scala title=HelloDocker.scala
object HelloDocker extends App {
println("Hello from Docker")
}
```

Passing `--docker` to the `package` sub-command generates a docker image. The docker image name parameter `--docker-image-repository` is mandatory.

The following command will generate `hello-docker` image with `latest` tag:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could one configure custom tag? If so I think we should add it to the guide


```bash
scala-cli package --docker HelloDocker.scala --docker-image-repository hello-docker
```

<!-- Expected:
Started building docker image with your application, it would take some time
Built docker image, run it with
docker run hello-docker:latest
-->

```bash
docker run hello-docker
# Hello from Docker
```

<!-- Expected:
Hello from Docker
-->

It is also supported to package your app in `JS` or `Native` environments.

```bash
scala-cli package --js --docker HelloDocker.scala --docker-image-repository hello-docker
```
<!-- Expected:
Started building docker image with your application, it would take some time
Built docker image, run it with
docker run hello-docker:latest
-->

Package scala native application to docker image is supported only on Linux.

```bash ignore
scala-cli package --native --docker HelloDocker.scala --docker-image-repository hello-docker
```
56 changes: 56 additions & 0 deletions website/docs/cookbooks/scala-docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
title: Package Scala application as a docker image
sidebar_position: 5
---

# Package Scala application as a docker image

ScalaCLI can create an executable application and package it into a docker image.

Here is a simple piece of code that will be executed in the docker container.

```scala title=HelloDocker.scala
object HelloDocker extends App {
println("Hello from Docker")
}
```

Passing `--docker` to the `package` sub-command generates a docker image. The docker image name parameter `--docker-image-repository` is mandatory.

The following command will generate `hello-docker` image with `latest` tag:

```bash
scala-cli package --docker HelloDocker.scala --docker-image-repository hello-docker
```

<!-- Expected:
Started building docker image with your application, it would take some time
Built docker image, run it with
docker run hello-docker:latest
-->

```bash
docker run hello-docker
# Hello from Docker
```

<!-- Expected:
Hello from Docker
-->

It is also supported to package your app in `JS` or `Native` environments.

```bash
scala-cli package --js --docker HelloDocker.scala --docker-image-repository hello-docker
```
<!-- Expected:
Started building docker image with your application, it would take some time
Built docker image, run it with
docker run hello-docker:latest
-->

Package scala native application to docker image is supported only on Linux.

```bash ignore
scala-cli package --native --docker HelloDocker.scala --docker-image-repository hello-docker
```