diff --git a/serving/samples/helloworld-clojure/Dockerfile b/serving/samples/helloworld-clojure/Dockerfile index 8b8e0894e41..ac1d66d5d40 100644 --- a/serving/samples/helloworld-clojure/Dockerfile +++ b/serving/samples/helloworld-clojure/Dockerfile @@ -13,9 +13,9 @@ COPY . . # Build an uberjar release artifact. RUN mv "$(lein uberjar | sed -n 's/^Created \(.*standalone\.jar\)/\1/p')" app-standalone.jar -# Configure and document the service HTTP port. +# Service must listen to $PORT environment variable. +# This default value facilitates local development. ENV PORT 8080 -EXPOSE $PORT # Run the web service on container startup. CMD ["java", "-jar", "app-standalone.jar"] diff --git a/serving/samples/helloworld-clojure/README.md b/serving/samples/helloworld-clojure/README.md index 84c16133712..b92df6f664b 100644 --- a/serving/samples/helloworld-clojure/README.md +++ b/serving/samples/helloworld-clojure/README.md @@ -59,29 +59,29 @@ recreate the source files from this folder. see [the clojure image documentation](https://github.com/docker-library/docs/tree/master/clojure). - ```docker - # Use the official Clojure image. - # https://hub.docker.com/_/clojure - FROM clojure + ```docker + # Use the official Clojure image. + # https://hub.docker.com/_/clojure + FROM clojure - # Create the project and download dependencies. - WORKDIR /usr/src/app - COPY project.clj . - RUN lein deps + # Create the project and download dependencies. + WORKDIR /usr/src/app + COPY project.clj . + RUN lein deps - # Copy local code to the container image. - COPY . . + # Copy local code to the container image. + COPY . . - # Build an uberjar release artifact. - RUN mv "$(lein uberjar | sed -n 's/^Created \(.*standalone\.jar\)/\1/p')" app-standalone.jar + # Build an uberjar release artifact. + RUN mv "$(lein uberjar | sed -n 's/^Created \(.*standalone\.jar\)/\1/p')" app-standalone.jar - # Configure and document the service HTTP port. - ENV PORT 8080 - EXPOSE $PORT + # Service must listen to $PORT environment variable. + # This default value facilitates local development. + ENV PORT 8080 - # Run the web service on container startup. - CMD ["java", "-jar", "app-standalone.jar"] - ``` + # Run the web service on container startup. + CMD ["java", "-jar", "app-standalone.jar"] + ``` 1. Create a new file, `service.yaml` and copy the following service definition into the file. Make sure to replace `{username}` with your Docker Hub diff --git a/serving/samples/helloworld-csharp/Dockerfile b/serving/samples/helloworld-csharp/Dockerfile index 1bf2cab0b56..10dd884c4da 100644 --- a/serving/samples/helloworld-csharp/Dockerfile +++ b/serving/samples/helloworld-csharp/Dockerfile @@ -14,9 +14,9 @@ COPY . . # Build a release artifact. RUN dotnet publish -c Release -o out -# Configure and document the service HTTP port. +# Service must listen to $PORT environment variable. +# This default value facilitates local development. ENV PORT 8080 -EXPOSE $PORT # Run the web service on container startup. CMD ["dotnet", "out/helloworld-csharp.dll"] diff --git a/serving/samples/helloworld-csharp/README.md b/serving/samples/helloworld-csharp/README.md index fe06d436c1e..dba6e3efdc1 100644 --- a/serving/samples/helloworld-csharp/README.md +++ b/serving/samples/helloworld-csharp/README.md @@ -55,30 +55,30 @@ recreate the source files from this folder. app, see [dockerizing a .NET core app](https://docs.microsoft.com/en-us/dotnet/core/docker/docker-basics-dotnet-core#dockerize-the-net-core-application). - ```docker - # Use Microsoft's official .NET image. - # https://hub.docker.com/r/microsoft/dotnet - FROM microsoft/dotnet:2.1-sdk - - # Install production dependencies. - # Copy csproj and restore as distinct layers. - WORKDIR /app - COPY *.csproj . - RUN dotnet restore - - # Copy local code to the container image. - COPY . . - - # Build a release artifact. - RUN dotnet publish -c Release -o out - - # Configure and document the service HTTP port. - ENV PORT 8080 - EXPOSE $PORT - - # Run the web service on container startup. - CMD ["dotnet", "out/helloworld-csharp.dll"] - ``` + ```docker + # Use Microsoft's official .NET image. + # https://hub.docker.com/r/microsoft/dotnet + FROM microsoft/dotnet:2.1-sdk + + # Install production dependencies. + # Copy csproj and restore as distinct layers. + WORKDIR /app + COPY *.csproj . + RUN dotnet restore + + # Copy local code to the container image. + COPY . . + + # Build a release artifact. + RUN dotnet publish -c Release -o out + + # Service must listen to $PORT environment variable. + # This default value facilitates local development. + ENV PORT 8080 + + # Run the web service on container startup. + CMD ["dotnet", "out/helloworld-csharp.dll"] + ``` 1. Create a new file, `service.yaml` and copy the following service definition into the file. Make sure to replace `{username}` with your Docker Hub diff --git a/serving/samples/helloworld-dart/Dockerfile b/serving/samples/helloworld-dart/Dockerfile index 6066d9c4d66..4d00aa6fbda 100644 --- a/serving/samples/helloworld-dart/Dockerfile +++ b/serving/samples/helloworld-dart/Dockerfile @@ -2,6 +2,6 @@ # https://hub.docker.com/r/google/dart-runtime/ FROM google/dart-runtime -# Configure and document the service HTTP port. +# Service must listen to $PORT environment variable. +# This default value facilitates local development. ENV PORT 8080 -EXPOSE $PORT diff --git a/serving/samples/helloworld-dart/README.md b/serving/samples/helloworld-dart/README.md index 766ad1e3208..25de5a26150 100644 --- a/serving/samples/helloworld-dart/README.md +++ b/serving/samples/helloworld-dart/README.md @@ -71,15 +71,15 @@ be created using the following instructions. 4. Create a new file named `Dockerfile`, this file defines instructions for dockerizing your applications, for dart apps this can be done as follows: - ```Dockerfile - # Use Google's official Dart image. - # https://hub.docker.com/r/google/dart-runtime/ - FROM google/dart-runtime - - # Configure and document the service HTTP port. - ENV PORT 8080 - EXPOSE $PORT - ``` + ```Dockerfile + # Use Google's official Dart image. + # https://hub.docker.com/r/google/dart-runtime/ + FROM google/dart-runtime + + # Service must listen to $PORT environment variable. + # This default value facilitates local development. + ENV PORT 8080 + ``` 5. Create a new file, `service.yaml` and copy the following service definition into the file. Make sure to replace `{username}` with your Docker Hub diff --git a/serving/samples/helloworld-elixir/Dockerfile b/serving/samples/helloworld-elixir/Dockerfile index fd5395a7614..37ae5ac71df 100644 --- a/serving/samples/helloworld-elixir/Dockerfile +++ b/serving/samples/helloworld-elixir/Dockerfile @@ -33,7 +33,6 @@ USER appuser ENV PORT=8080 MIX_ENV=prod REPLACE_OS_VARS=true WORKDIR /opt/app -EXPOSE 8080 COPY --from=0 /opt/release . ENV RUNNER_LOG_DIR /var/log CMD ["/opt/app/bin/start_server", "foreground", "boot_var=/tmp"] diff --git a/serving/samples/helloworld-elixir/README.md b/serving/samples/helloworld-elixir/README.md index e567b9f265a..f078a76b3f6 100644 --- a/serving/samples/helloworld-elixir/README.md +++ b/serving/samples/helloworld-elixir/README.md @@ -84,7 +84,6 @@ When asked, if you want to `Fetch and install dependencies? [Yn]` select `y` # Document that the service listens on port 8080. ENV PORT=8080 MIX_ENV=prod REPLACE_OS_VARS=true WORKDIR /opt/app - EXPOSE 8080 COPY --from=0 /opt/release . ENV RUNNER_LOG_DIR /var/log diff --git a/serving/samples/helloworld-go/Dockerfile b/serving/samples/helloworld-go/Dockerfile index cc8b481c3e4..6e91928c31c 100644 --- a/serving/samples/helloworld-go/Dockerfile +++ b/serving/samples/helloworld-go/Dockerfile @@ -19,9 +19,9 @@ FROM alpine # Copy the binary to the production image from the builder stage. COPY --from=builder /go/src/github.com/knative/docs/helloworld/helloworld /helloworld -# Configure and document the service HTTP port. +# Service must listen to $PORT environment variable. +# This default value facilitates local development. ENV PORT 8080 -EXPOSE $PORT # Run the web service on container startup. CMD ["/helloworld"] diff --git a/serving/samples/helloworld-go/README.md b/serving/samples/helloworld-go/README.md index 607ce7f626c..b1b26d25767 100644 --- a/serving/samples/helloworld-go/README.md +++ b/serving/samples/helloworld-go/README.md @@ -80,9 +80,9 @@ recreate the source files from this folder. # Copy the binary to the production image from the builder stage. COPY --from=builder /go/src/github.com/knative/docs/helloworld/helloworld /helloworld - # Configure and document the service HTTP port. + # Service must listen to $PORT environment variable. + # This default value facilitates local development. ENV PORT 8080 - EXPOSE $PORT # Run the web service on container startup. CMD ["/helloworld"] diff --git a/serving/samples/helloworld-haskell/Dockerfile b/serving/samples/helloworld-haskell/Dockerfile index 3a5871619e5..ec479234c68 100644 --- a/serving/samples/helloworld-haskell/Dockerfile +++ b/serving/samples/helloworld-haskell/Dockerfile @@ -18,9 +18,9 @@ FROM fpco/haskell-scratch:integer-gmp WORKDIR /root/ COPY --from=builder /root/.local/bin/helloworld-haskell-exe . -# Configure and document the service HTTP port. +# Service must listen to $PORT environment variable. +# This default value facilitates local development. ENV PORT 8080 -EXPOSE $PORT # Run the web service on container startup. CMD ["./helloworld-haskell-exe"] diff --git a/serving/samples/helloworld-haskell/README.md b/serving/samples/helloworld-haskell/README.md index 84a6cefe998..c53bffdc6fc 100644 --- a/serving/samples/helloworld-haskell/README.md +++ b/serving/samples/helloworld-haskell/README.md @@ -80,34 +80,34 @@ recreate the source files from this folder. 1. In your project directory, create a file named `Dockerfile` and copy the code block below into it. - ```docker - # Use the official Haskell image to create a build artifact. - # https://hub.docker.com/_/haskell/ - FROM haskell:8.2.2 as builder - - # Copy local code to the container image. - WORKDIR /app - COPY . . - - # Build and test our code, then build the “helloworld-haskell-exe” executable. - RUN stack setup - RUN stack build --copy-bins - - # Use a Docker multi-stage build to create a lean production image. - # https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds - FROM fpco/haskell-scratch:integer-gmp - - # Copy the "helloworld-haskell-exe" executable from the builder stage to the production image. - WORKDIR /root/ - COPY --from=builder /root/.local/bin/helloworld-haskell-exe . - - # Configure and document the service HTTP port. - ENV PORT 8080 - EXPOSE $PORT - - # Run the web service on container startup. - CMD ["./helloworld-haskell-exe"] - ``` + ```docker + # Use the official Haskell image to create a build artifact. + # https://hub.docker.com/_/haskell/ + FROM haskell:8.2.2 as builder + + # Copy local code to the container image. + WORKDIR /app + COPY . . + + # Build and test our code, then build the “helloworld-haskell-exe” executable. + RUN stack setup + RUN stack build --copy-bins + + # Use a Docker multi-stage build to create a lean production image. + # https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds + FROM fpco/haskell-scratch:integer-gmp + + # Copy the "helloworld-haskell-exe" executable from the builder stage to the production image. + WORKDIR /root/ + COPY --from=builder /root/.local/bin/helloworld-haskell-exe . + + # Service must listen to $PORT environment variable. + # This default value facilitates local development. + ENV PORT 8080 + + # Run the web service on container startup. + CMD ["./helloworld-haskell-exe"] + ``` 1. Create a new file, `service.yaml` and copy the following service definition into the file. Make sure to replace `{username}` with your Docker Hub diff --git a/serving/samples/helloworld-java/Dockerfile b/serving/samples/helloworld-java/Dockerfile index 6e2290853d8..159b36e5f8c 100644 --- a/serving/samples/helloworld-java/Dockerfile +++ b/serving/samples/helloworld-java/Dockerfile @@ -18,10 +18,9 @@ FROM openjdk:8-jre-alpine # Copy the jar to the production image from the builder stage. COPY --from=builder /app/target/helloworld-*.jar /helloworld.jar -# Configure and document the service HTTP port. +# Service must listen to $PORT environment variable. +# This default value facilitates local development. ENV PORT 8080 -EXPOSE $PORT # Run the web service on container startup. CMD ["java","-Djava.security.egd=file:/dev/./urandom","-Dserver.port=${PORT}","-jar","/helloworld.jar"] - diff --git a/serving/samples/helloworld-java/README.md b/serving/samples/helloworld-java/README.md index ec5f67deedd..7935d58061d 100644 --- a/serving/samples/helloworld-java/README.md +++ b/serving/samples/helloworld-java/README.md @@ -86,34 +86,34 @@ recreate the source files from this folder. For additional information on multi-stage docker builds for Java see [Creating Smaller Java Image using Docker Multi-stage Build](http://blog.arungupta.me/smaller-java-image-docker-multi-stage-build/). - ```docker - # Use the official maven/Java 8 image to create a build artifact. - # https://hub.docker.com/_/maven - FROM maven:3.5-jdk-8-alpine as builder - - # Copy local code to the container image. - WORKDIR /app - COPY pom.xml . - COPY src ./src - - # Build a release artifact. - RUN mvn package -DskipTests - - # Use the Official OpenJDK image for a lean production stage of our multi-stage build. - # https://hub.docker.com/_/openjdk - # https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds - FROM openjdk:8-jre-alpine - - # Copy the jar to the production image from the builder stage. - COPY --from=builder /app/target/helloworld-*.jar /helloworld.jar - - # Configure and document the service HTTP port. - ENV PORT 8080 - EXPOSE $PORT - - # Run the web service on container startup. - CMD ["java","-Djava.security.egd=file:/dev/./urandom","-Dserver.port=${PORT}","-jar","/helloworld.jar"] - ``` + ```docker + # Use the official maven/Java 8 image to create a build artifact. + # https://hub.docker.com/_/maven + FROM maven:3.5-jdk-8-alpine as builder + + # Copy local code to the container image. + WORKDIR /app + COPY pom.xml . + COPY src ./src + + # Build a release artifact. + RUN mvn package -DskipTests + + # Use the Official OpenJDK image for a lean production stage of our multi-stage build. + # https://hub.docker.com/_/openjdk + # https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds + FROM openjdk:8-jre-alpine + + # Copy the jar to the production image from the builder stage. + COPY --from=builder /app/target/helloworld-*.jar /helloworld.jar + + # Service must listen to $PORT environment variable. + # This default value facilitates local development. + ENV PORT 8080 + + # Run the web service on container startup. + CMD ["java","-Djava.security.egd=file:/dev/./urandom","-Dserver.port=${PORT}","-jar","/helloworld.jar"] + ``` 1. Create a new file, `service.yaml` and copy the following service definition into the file. Make sure to replace `{username}` with your Docker Hub diff --git a/serving/samples/helloworld-kotlin/Dockerfile b/serving/samples/helloworld-kotlin/Dockerfile index 4eb2de019a7..69d23f8c2d1 100644 --- a/serving/samples/helloworld-kotlin/Dockerfile +++ b/serving/samples/helloworld-kotlin/Dockerfile @@ -17,9 +17,9 @@ FROM openjdk:8-jre-alpine # Copy the jar to the production image from the builder stage. COPY --from=builder /home/gradle/build/libs/gradle.jar /helloworld.jar -# Configure and document the service HTTP port. +# Service must listen to $PORT environment variable. +# This default value facilitates local development. ENV PORT 8080 -EXPOSE $PORT # Run the web service on container startup. CMD [ "java", "-jar", "-Djava.security.egd=file:/dev/./urandom", "/helloworld.jar" ] diff --git a/serving/samples/helloworld-kotlin/README.md b/serving/samples/helloworld-kotlin/README.md index 34011446ad1..e73107babe2 100644 --- a/serving/samples/helloworld-kotlin/README.md +++ b/serving/samples/helloworld-kotlin/README.md @@ -108,33 +108,33 @@ recreate the source files from this folder. 5. Create a file named `Dockerfile` and copy the code block below into it. - ```docker - # Use the official gradle image to create a build artifact. - # https://hub.docker.com/_/gradle - FROM gradle as builder + ```docker + # Use the official gradle image to create a build artifact. + # https://hub.docker.com/_/gradle + FROM gradle as builder - # Copy local code to the container image. - COPY build.gradle . - COPY src ./src + # Copy local code to the container image. + COPY build.gradle . + COPY src ./src - # Build a release artifact. - RUN gradle clean build --no-daemon + # Build a release artifact. + RUN gradle clean build --no-daemon - # Use the Official OpenJDK image for a lean production stage of our multi-stage build. - # https://hub.docker.com/_/openjdk - # https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds - FROM openjdk:8-jre-alpine + # Use the Official OpenJDK image for a lean production stage of our multi-stage build. + # https://hub.docker.com/_/openjdk + # https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds + FROM openjdk:8-jre-alpine - # Copy the jar to the production image from the builder stage. - COPY --from=builder /home/gradle/build/libs/gradle.jar /helloworld.jar + # Copy the jar to the production image from the builder stage. + COPY --from=builder /home/gradle/build/libs/gradle.jar /helloworld.jar - # Configure and document the service HTTP port. - ENV PORT 8080 - EXPOSE $PORT + # Service must listen to $PORT environment variable. + # This default value facilitates local development. + ENV PORT 8080 - # Run the web service on container startup. - CMD [ "java", "-jar", "-Djava.security.egd=file:/dev/./urandom", "/helloworld.jar" ] - ``` + # Run the web service on container startup. + CMD [ "java", "-jar", "-Djava.security.egd=file:/dev/./urandom", "/helloworld.jar" ] + ``` 6. Create a new file, `service.yaml` and copy the following service definition into the file. Make sure to replace `{username}` with your Docker Hub diff --git a/serving/samples/helloworld-nodejs/Dockerfile b/serving/samples/helloworld-nodejs/Dockerfile index 860bb4cfb52..91cf8742e3b 100644 --- a/serving/samples/helloworld-nodejs/Dockerfile +++ b/serving/samples/helloworld-nodejs/Dockerfile @@ -16,9 +16,9 @@ RUN npm install --only=production # Copy local code to the container image. COPY . . -# Configure and document the service HTTP port. +# Service must listen to $PORT environment variable. +# This default value facilitates local development. ENV PORT 8080 -EXPOSE $PORT # Run the web service on container startup. CMD [ "npm", "start" ] diff --git a/serving/samples/helloworld-nodejs/README.md b/serving/samples/helloworld-nodejs/README.md index c83e95891a4..e0942618353 100644 --- a/serving/samples/helloworld-nodejs/README.md +++ b/serving/samples/helloworld-nodejs/README.md @@ -83,11 +83,12 @@ recreate the source files from this folder. see [Dockerizing a Node.js web app](https://nodejs.org/en/docs/guides/nodejs-docker-webapp/). + ```Dockerfile # Use the official Node.js 10 image. # https://hub.docker.com/_/node FROM node:10 - + # Create and change to the app directory. WORKDIR /usr/src/app @@ -102,9 +103,9 @@ recreate the source files from this folder. # Copy local code to the container image. COPY . . - # Configure and document the service HTTP port. + # Service must listen to $PORT environment variable. + # This default value facilitates local development. ENV PORT 8080 - EXPOSE $PORT # Run the web service on container startup. CMD [ "npm", "start" ] diff --git a/serving/samples/helloworld-php/Dockerfile b/serving/samples/helloworld-php/Dockerfile index 9c1f0b0d91b..7b95fe59a5e 100644 --- a/serving/samples/helloworld-php/Dockerfile +++ b/serving/samples/helloworld-php/Dockerfile @@ -14,6 +14,6 @@ RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-available/000-default.conf /etc/a # https://hub.docker.com/_/php#configuration RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" -# Configure and document the service HTTP port. +# Service must listen to $PORT environment variable. +# This default value facilitates local development. ENV PORT 8080 -EXPOSE $PORT diff --git a/serving/samples/helloworld-php/README.md b/serving/samples/helloworld-php/README.md index 7206e800d0c..09764000b8f 100644 --- a/serving/samples/helloworld-php/README.md +++ b/serving/samples/helloworld-php/README.md @@ -36,27 +36,27 @@ recreate the source files from this folder. 1. Create a file named `Dockerfile` and copy the code block below into it. See [official PHP docker image](https://hub.docker.com/_/php/) for more details. - ```docker - # Use the official PHP 7.2 image. - # https://hub.docker.com/_/php - FROM php:7.2.6-apache - - # Copy local code to the container image. - COPY index.php /var/www/html/ - - # Use the PORT environment variable in Apache configuration files. - RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf - - # Configure PHP for development. - # Switch to the production php.ini for production operations. - # RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" - # https://hub.docker.com/_/php#configuration - RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" - - # Configure and document the service HTTP port. - ENV PORT 8080 - EXPOSE $PORT - ``` + ```docker + # Use the official PHP 7.2 image. + # https://hub.docker.com/_/php + FROM php:7.2.6-apache + + # Copy local code to the container image. + COPY index.php /var/www/html/ + + # Use the PORT environment variable in Apache configuration files. + RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf + + # Configure PHP for development. + # Switch to the production php.ini for production operations. + # RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" + # https://hub.docker.com/_/php#configuration + RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" + + # Service must listen to $PORT environment variable. + # This default value facilitates local development. + ENV PORT 8080 + ``` 1. Create a new file, `service.yaml` and copy the following service definition into the file. Make sure to replace `{username}` with your Docker Hub diff --git a/serving/samples/helloworld-python/Dockerfile b/serving/samples/helloworld-python/Dockerfile index 1875f5bdec8..e0bfa7b3118 100644 --- a/serving/samples/helloworld-python/Dockerfile +++ b/serving/samples/helloworld-python/Dockerfile @@ -10,9 +10,9 @@ COPY . . # Install production dependencies. RUN pip install Flask -# Configure and document the service HTTP port. +# Service must listen to $PORT environment variable. +# This default value facilitates local development. ENV PORT 8080 -EXPOSE $PORT # Run the web service on container startup. CMD ["python", "app.py"] diff --git a/serving/samples/helloworld-python/README.md b/serving/samples/helloworld-python/README.md index 20582103907..03efd2219a0 100644 --- a/serving/samples/helloworld-python/README.md +++ b/serving/samples/helloworld-python/README.md @@ -47,26 +47,26 @@ recreate the source files from this folder. [official Python docker image](https://hub.docker.com/_/python/) for more details. - ```docker - # Use the official Python image. - # https://hub.docker.com/_/python - FROM python - - # Copy local code to the container image. - ENV APP_HOME /app - WORKDIR $APP_HOME - COPY . . - - # Install production dependencies. - RUN pip install Flask - - # Configure and document the service HTTP port. - ENV PORT 8080 - EXPOSE $PORT - - # Run the web service on container startup. - CMD ["python", "app.py"] - ``` + ```docker + # Use the official Python image. + # https://hub.docker.com/_/python + FROM python + + # Copy local code to the container image. + ENV APP_HOME /app + WORKDIR $APP_HOME + COPY . . + + # Install production dependencies. + RUN pip install Flask + + # Service must listen to $PORT environment variable. + # This default value facilitates local development. + ENV PORT 8080 + + # Run the web service on container startup. + CMD ["python", "app.py"] + ``` 1. Create a new file, `service.yaml` and copy the following service definition into the file. Make sure to replace `{username}` with your Docker Hub diff --git a/serving/samples/helloworld-ruby/Dockerfile b/serving/samples/helloworld-ruby/Dockerfile index 7077135d8a8..c3114cb495f 100644 --- a/serving/samples/helloworld-ruby/Dockerfile +++ b/serving/samples/helloworld-ruby/Dockerfile @@ -11,9 +11,9 @@ RUN bundle install # Copy local code to the container image. COPY . . -# Configure and document the service HTTP port. +# Service must listen to $PORT environment variable. +# This default value facilitates local development. ENV PORT 8080 -EXPOSE $PORT # Run the web service on container startup. CMD ["ruby", "./app.rb"] diff --git a/serving/samples/helloworld-ruby/README.md b/serving/samples/helloworld-ruby/README.md index 96e9116b123..2456f1cfd43 100644 --- a/serving/samples/helloworld-ruby/README.md +++ b/serving/samples/helloworld-ruby/README.md @@ -42,27 +42,27 @@ recreate the source files from this folder. [official Ruby docker image](https://hub.docker.com/_/ruby/) for more details. - ```docker - # Use the official Ruby image. - # https://hub.docker.com/_/ruby - FROM ruby:2.5 - - # Install production dependencies. - WORKDIR /usr/src/app - COPY Gemfile Gemfile.lock ./ - ENV BUNDLE_FROZEN=true - RUN bundle install - - # Copy local code to the container image. - COPY . . - - # Configure and document the service HTTP port. - ENV PORT 8080 - EXPOSE $PORT - - # Run the web service on container startup. - CMD ["ruby", "./app.rb"] - ``` + ```docker + # Use the official Ruby image. + # https://hub.docker.com/_/ruby + FROM ruby:2.5 + + # Install production dependencies. + WORKDIR /usr/src/app + COPY Gemfile Gemfile.lock ./ + ENV BUNDLE_FROZEN=true + RUN bundle install + + # Copy local code to the container image. + COPY . . + + # Service must listen to $PORT environment variable. + # This default value facilitates local development. + ENV PORT 8080 + + # Run the web service on container startup. + CMD ["ruby", "./app.rb"] + ``` 1. Create a file named `Gemfile` and copy the text block below into it. diff --git a/serving/samples/helloworld-rust/Dockerfile b/serving/samples/helloworld-rust/Dockerfile index 84d3c30c18e..10073fc6c2f 100644 --- a/serving/samples/helloworld-rust/Dockerfile +++ b/serving/samples/helloworld-rust/Dockerfile @@ -9,9 +9,9 @@ COPY . . # Install production dependencies and build a release artifact. RUN cargo install -# Configure and document the service HTTP port. +# Service must listen to $PORT environment variable. +# This default value facilitates local development. ENV PORT 8080 -EXPOSE $PORT # Run the web service on container startup. CMD ["hellorust"] diff --git a/serving/samples/helloworld-rust/README.md b/serving/samples/helloworld-rust/README.md index 69b5a7312e7..6fa175cd7b7 100644 --- a/serving/samples/helloworld-rust/README.md +++ b/serving/samples/helloworld-rust/README.md @@ -87,25 +87,25 @@ recreate the source files from this folder. 1. In your project directory, create a file named `Dockerfile` and copy the code block below into it. - ```docker - # Use the official Rust image. - # https://hub.docker.com/_/rust - FROM rust:1.27.0 + ```docker + # Use the official Rust image. + # https://hub.docker.com/_/rust + FROM rust:1.27.0 - # Copy local code to the container image. - WORKDIR /usr/src/app - COPY . . + # Copy local code to the container image. + WORKDIR /usr/src/app + COPY . . - # Install production dependencies and build a release artifact. - RUN cargo install + # Install production dependencies and build a release artifact. + RUN cargo install - # Configure and document the service HTTP port. - ENV PORT 8080 - EXPOSE $PORT + # Service must listen to $PORT environment variable. + # This default value facilitates local development. + ENV PORT 8080 - # Run the web service on container startup. - CMD ["hellorust"] - ``` + # Run the web service on container startup. + CMD ["hellorust"] + ``` 1. Create a new file, `service.yaml` and copy the following service definition into the file. Make sure to replace `{username}` with your Docker Hub diff --git a/serving/samples/helloworld-vertx/Dockerfile b/serving/samples/helloworld-vertx/Dockerfile index 5bbee10eda9..0fe5bec6cb5 100644 --- a/serving/samples/helloworld-vertx/Dockerfile +++ b/serving/samples/helloworld-vertx/Dockerfile @@ -1,5 +1,11 @@ +# Use fabric8's s2i Builder image. +# https://hub.docker.com/r/fabric8/s2i-java FROM fabric8/s2i-java:2.0 + +# Service must listen to $PORT environment variable. +# This default value facilitates local development. +ENV PORT 8080 + +# Copy the JAR file to the deployment directory. ENV JAVA_APP_DIR=/deployments -EXPOSE 8080 COPY target/helloworld-1.0.0-SNAPSHOT.jar /deployments/ - diff --git a/serving/samples/helloworld-vertx/README.md b/serving/samples/helloworld-vertx/README.md index 0ef5345b664..80220d51a79 100644 --- a/serving/samples/helloworld-vertx/README.md +++ b/serving/samples/helloworld-vertx/README.md @@ -143,12 +143,19 @@ To create and configure the source files in the root of your working directory: 1. Create the `Dockerfile` file: - ```docker - FROM fabric8/s2i-java:2.0 - ENV JAVA_APP_DIR=/deployments - EXPOSE 8080 - COPY target/helloworld-1.0.0-SNAPSHOT.jar /deployments/ - ``` + ```docker + # Use fabric8's s2i Builder image. + # https://hub.docker.com/r/fabric8/s2i-java + FROM fabric8/s2i-java:2.0 + + # Service must listen to $PORT environment variable. + # This default value facilitates local development. + ENV PORT 8080 + + # Copy the JAR file to the deployment directory. + ENV JAVA_APP_DIR=/deployments + COPY target/helloworld-1.0.0-SNAPSHOT.jar /deployments/ + ``` 1. Create the `service.yaml` file. You must specify your Docker Hub username in `{username}`. You can also configure the `TARGET`, for example you can modify