Запуск HTTP-сервера Grizzly в контейнере FargateJAVA

Программисты JAVA общаются здесь
Ответить
Гость
 Запуск HTTP-сервера Grizzly в контейнере Fargate

Сообщение Гость »


String baseUri = http://127.0.0.1:8080/abc HttpServer grizzlyServer = startServer(baseUri); while (grizzlyServer.isStarted()) { TimeUnit.SECONDS.sleep(1); loopCount++; loopCount = loopCount%60; if (loopCount == 0) { logger.finest("I am still Running"); } } try { grizzlyServer.shutdown().get(); } catch (Exception e) { logger.warning("Exception stopping HTTP Server: " + e.getLocalizedMessage()); } /** * Starts the grizzly HTTP server for providing the REST capabilities * * @param baseUri the base uri of the server * @return the grizzly http server */ public static HttpServer startServer(String baseUri) { // create a resource config that scans for JAX-RS resources and providers in the given package final ResourceConfig rc = new ResourceConfig().packages("com.api"); rc.property(ServerProperties.WADL_FEATURE_DISABLE, true); // disable WADL as we don't use it and it generates runtime warnings // Register the provider binder - implements jakarta.ws.rs.core.Feature. Then we have some other classes with @Path and @GET annotations, and the provider here is @Inject-ed, so we have access to it. rc.register(new ServiceProviderBinder()); // create and start a new instance of grizzly http server // exposing the Jersey application at BASE_URI HttpServer server = GrizzlyHttpServerFactory.createHttpServer(URI.create(baseUri), rc); Logger l = Logger.getLogger("org.glassfish.grizzly.http.server.HttpHandler"); l.setLevel(Level.FINE); l.setUseParentHandlers(false); ConsoleHandler ch = new ConsoleHandler(); ch.setLevel(Level.ALL); l.addHandler(ch); return server; } I can use this approach to start up the server locally, or in a docker container than is run locally using docker-compose up.

If, however, I then deploy this same container to fargate through an ECS Task Definition and service, I get the following in Cloudwatch:

jakarta.ws.rs.ProcessingException: Failed to start Grizzly HTTP server: Address already in use

My Task definition configuration contains a port mapping 8080:8080 -


Изображение


and my Dockerfile is as follows (with the details passed in from docker-compose):

FROM eclipse-temurin:21.0.1_12-jdk ARG SERVICE_NAME ARG APP_DIR=/opt/app RUN mkdir -p ${APP_DIR} COPY ${SERVICE_NAME}.sh ${APP_DIR} COPY dependencies ${APP_DIR}/dependencies COPY ${SERVICE_NAME}.jar ${APP_DIR} COPY ${SERVICE_NAME}.awstest.properties ${APP_DIR} USER root RUN chmod -R 777 ${APP_DIR} # When the container starts, run the svt startup script ENV SERVICESCRIPT=${APP_DIR}/${SERVICE_NAME}.sh CMD exec $SERVICESCRIPT What do I need to change in my configuration, either in code, Docker or AWS, in order to get this working? Why is port 8080 already in use on the fargate container?


Источник: https://stackoverflow.com/questions/781 ... -container
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»