Java 11 Custom Runtime

365 views
Skip to first unread message

Anatoli Trifonov

unread,
Jun 16, 2021, 2:54:15 AM6/16/21
to Google App Engine
I am looking at this page https://cloud.google.com/appengine/docs/flexible/custom-runtimes/quickstart
and it is close to impossible to figure out if GCP has a maintained docker file for Java 11 that I can use to create Java 11 Custom Runtime to deploy to Flex environment.

Does anyone have a good Docker file example that I can use to create a Custom runtime for Java 11?

Thank you
A

Jordi (Google Cloud Platform Support)

unread,
Jun 22, 2021, 4:24:00 AM6/22/21
to Google App Engine
Hello, 

After some time reproducing, I've finally got Java 11 running on App Engine Flex. As the name says, Flexible lets you run any custom runtime [1] that has some basic rules [2].
In this case, it is just necessary an app.yaml, Dockerfile and in my case a simple TimeServer that is listening on port 8080 [3] 

[3] https://cloud.google.com/appengine/docs/flexible/custom-runtimes/build#listening_to_port_8080

----------------------------

app.yaml

runtime: custom

env: flex

----------------------------

Dockerfile

FROM adoptopenjdk/openjdk11:ubi

COPY . /usr/src/myapp

WORKDIR /usr/src/myapp

RUN javac TimeServer.java

CMD ["java", "TimeServer"]

----------------------------

TimeServer.java

import java.io.*;

import java.net.*;

import java.util.Date;

public class TimeServer {

   public static void main(String[] args) {

       try (ServerSocket serverSocket = new ServerSocket(8080)) {

           System.out.println("Server is listening");

           while (true) {

               Socket socket = serverSocket.accept();

               System.out.println("New client connected");

               OutputStream output = socket.getOutputStream();

               PrintWriter writer = new PrintWriter(output, true);

               writer.println(new Date().toString());

           }

       } catch (IOException ex) {

           System.out.println("Server exception: " + ex.getMessage());

           ex.printStackTrace();

       }

   }

}


----------------------------


Reply all
Reply to author
Forward
0 new messages