Skip to content

Commit

Permalink
add Dockerfile examples (#149)
Browse files Browse the repository at this point in the history
* add Dockerfile examples

* specify nodejs dockerfile version
  • Loading branch information
salrashid123 authored and dlorenc committed Dec 7, 2017
1 parent 254fa1a commit d061f89
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 3 deletions.
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ Follow these steps to get started:
The basic idea is that you'll have one stage to build your application artifacts, and insert them into your runtime distroless image.
If you'd like to learn more, please see the documentation on [multi-stage builds](https://docs.docker.com/engine/userguide/eng-image/multistage-build/).

Here's a quick example.
```

#### Examples with Docker
Here's a quick example for go:

```dockerfile
# Start by building the application.
FROM golang:1.8 as build

Expand All @@ -55,6 +58,22 @@ Follow these steps to get started:
CMD ["/app"]
```

You can find other examples here:


* [Java](examples/java/Dockerfile)
* [Python](examples/python2.7/Dockerfile)
* [Python 3](examples/python3/Dockerfile)
* [Golang](examples/go/Dockerfile)
* [Node.js](examples/nodejs/Dockerfile)
* [dotnet](examples/dotnet/Dockerfile)

To run any example, go the the directory for the language and run
```
docker build -t myapp .
docker run -t myapp
```

### Bazel

For full documentation on how to use bazel to generate Docker images, see the [bazelbuild/rules_docker](http://github.com/bazelbuild/rules_docker) repository.
Expand All @@ -63,7 +82,7 @@ For documentation and examples on how to use the bazel package manager rules, se

Examples can be found in this repository in the [examples](examples/) directory.

## Examples
#### Examples with Bazel

We have some examples on how to run some common application stacks in the /examples directory.
See here for:
Expand Down
11 changes: 11 additions & 0 deletions examples/dotnet/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM microsoft/dotnet:2.0.0-sdk AS build-env
ADD . /app
WORKDIR /app
RUN dotnet restore -r linux-x64
RUN dotnet publish -c Release -r linux-x64

FROM gcr.io/distroless/dotnet
WORKDIR /app
COPY --from=build-env /app /app/
#CMD ["dotnet", "bin/Release/netcoreapp2.0/linux-x64/publish/hello.dll"]
CMD ["bin/Release/netcoreapp2.0/linux-x64/publish/hello"]
11 changes: 11 additions & 0 deletions examples/go/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:1.8 as build-env

WORKDIR /go/src/app
ADD . /go/src/app

RUN go-wrapper download # "go get -d -v ./..."
RUN go-wrapper install

FROM gcr.io/distroless/base
COPY --from=build-env /go/bin/app /
CMD ["/app"]
10 changes: 10 additions & 0 deletions examples/java/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM openjdk:8-jdk-slim AS build-env
ADD . /app/examples
WORKDIR /app
RUN javac examples/*.java
RUN jar cfe main.jar examples.HelloJava examples/*.class

FROM gcr.io/distroless/java
COPY --from=build-env /app /app
WORKDIR /app
CMD ["main.jar"]
8 changes: 8 additions & 0 deletions examples/nodejs/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM node:8.9.1 AS build-env
ADD . /app
WORKDIR /app

FROM gcr.io/distroless/nodejs
COPY --from=build-env /app /app
WORKDIR /app
CMD ["hello.js"]
8 changes: 8 additions & 0 deletions examples/python2.7/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:2.7-slim AS build-env
ADD . /app
WORKDIR /app

FROM gcr.io/distroless/python2.7
COPY --from=build-env /app /app
WORKDIR /app
CMD ["hello.py", "/etc"]
8 changes: 8 additions & 0 deletions examples/python3/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3-slim AS build-env
ADD . /app
WORKDIR /app

FROM gcr.io/distroless/python3
COPY --from=build-env /app /app
WORKDIR /app
CMD ["hello.py", "/etc"]

0 comments on commit d061f89

Please sign in to comment.