Container didn't respond to HTTP pings on port: 3000, - .net-5

I created a .NET 5 ASP.NET web application with a Dockerfile below.
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /source
# copy csproj and restore as distinct layers
COPY *.csproj .
RUN dotnet restore
# copy and publish app and libraries
COPY . .
RUN dotnet publish -c release -o /app --no-restore
# final stage/image
FROM mcr.microsoft.com/dotnet/runtime:5.0
EXPOSE 3000
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["./TestNET5"]
I added the variables PORT and WEBSITES_PORT with values 3000 in the Configuration settings of the Azure Web App and I also added -e environment=Production -e ASPNETCORE_ENVIRONMENT=Production but I am still getting the error below.
Container xxx didn't respond to HTTP pings on port: 3000, failing site start. See container logs for debugging.
Is there I'm missing here? I already checked several articles but I couldn't seem to find a solution.

If all the things have been done as you said, then the possible reason is that your image does not work well.
Below I will list all the things you have to do to deploy your application image to Azure App Service:
make sure the image can work well locally;
set the environment variable WEBSITES_PORT if the port the container exposed is not 80 or 443, here its value is 3000;
set the environment variables for the docker registry to authenticate if it's private, for example, if you push the image to ACR.

Related

Pass Spring Boot port through Docker run

I want to run the same application on multiple containers on the same Docker network, I have another application that will start the docker containers, the issue is the number of containers is undefined, so I want to pass the ports when I run the image not build it, by default the container will run on port 8080, but when a new container starts it will also try to run on 8080, therefore I want to change the port to not cause the other containers to fail.
Here is the Dockerfile for the application:
FROM maven:3.8.6-openjdk-18-slim as BUILD
WORKDIR /usr/src/app
#Download dependencies
COPY pom.xml ./
RUN ["/usr/local/bin/mvn-entrypoint.sh", "mvn", "verify", "clean", "--fail-never"]
#Create war file
COPY ./src ./src
RUN mvn -f ./pom.xml package
FROM openjdk:18.0.2.1-jdk-slim
ARG port
ENV PORT $port
WORKDIR /usr/src/app
COPY --from=BUILD /usr/src/app/target/*.war /usr/src/app/*.war
ENTRYPOINT java -jar "/usr/src/app/*.war" --server.port=$PORT
EXPOSE $PORT
if I use --build-arg it works since it's using the ARG port, but since I want to set it on run time so I made an environmental variable.
If I run docker run -it <container_id> -e "PORT=8085" the application still runs on 8080 or the --build-arg if provided.
Is there a way to provide the port when using docker run instead of building the same image every single time I want it to run on a different port?
There should be no conflict if multiple containers are using the same port since each container has a different IP address, which can be verified with docker container inspect NAME|ID.

Access Tomcat debug port outside container

I have a container running java backend on a tomcat server. I would like to configure it so that I can attach my eclipse to debug my code.
There is a lot of documentation but with so many different and contradictory answers, I can't find a way to do it.
here is my current configuration :
DockerFile :
From tomcat:9.0-jdk8-openjdk
ADD ./application.war /usr/local/tomcat/webapps/
ADD tomcat-users.xml /usr/local/tomcat/conf/tomcat-users.xml
ADD server.xml /usr/local/tomcat/conf/server.xml
EXPOSE 9090
CMD ["catalina.sh","run"]
And the command to run the docker :
docker run -d -p 9090:8080 myApp
What should I add to make my application accessible to remote debugging ?
the solution I found was :
DockerFile
From tomcat:9.0-jdk8-openjdk
ADD ./application.war /usr/local/tomcat/webapps/
ADD tomcat-users.xml /usr/local/tomcat/conf/tomcat-users.xml
ADD server.xml /usr/local/tomcat/conf/server.xml
EXPOSE 9090
EXPOSE 9000
ENV JPDA_ADDRESS=8000
ENV JPDA_TRANSPORT=dt_socket
CMD ["catalina.sh", "jpda", "run"]
and then :
docker run -d -p 9090:8080 -p 9000:8000 myApp after building the image.
Warning : this makes the application debuggable only from the server where the docker is running (in localhost:9000 in that example)! I read there is something to do with *:JPDA_ADDRESS but I could not make it work.

Docker map port is invalid

I followed the tutorial to compile the project's image file with gradle and type it into docker. At the same time, the image is run and the virtual port is mapped to port 8761. However, my host accesses port 8761 and cannot connect. At the same time, I start the project locally and the host 8761 can be used.
I modified the dependent jdk8 image and added EXPOSE to the dockerfile.
Below are the configuration files and the docker run command:
FROM gmaslowski/jdk
VOLUME /tmp
ADD his-eureka-server-one-0.0.1-SNAPSHOT.jar app.jar
#RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-
jar","/app.jar"]
EXPOSE 8760
docker run -d -t -p 127.0.0.1:8760:8760 com.anhuishangjue/his-eureka-
server-one:0.0.1-SNAPSHOT
I want the host's 127.0.0.1:8760 to be able to access the eureka registry, but he told me to deny access

docker ports not available

I have a spring-config-sever project that I am trying to run via Docker. I can run it from the command line and my other services and browser successfully connect via:
http://localhost:8980/aservice/dev
However, if I run it via Docker, the call fails.
My config-server has a Dockerfile:
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE=build/libs/my-config-server-0.1.0.jar
ADD ${JAR_FILE} my-config-server-0.1.0.jar
EXPOSE 8980
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/my-config-server-0.1.0.jar"]
I build via:
docker build -t my-config-server .
I am running it via:
docker run my-config-server -p 8980:8980
And then I confirm it is running via
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1cecafdf99fe my-config-server "java -Djava.securit…" 14 seconds ago Up 13 seconds 8980/tcp suspicious_brahmagupta
When I run it via Docker, the browse fails with a "ERR_CONNECTION_REFUSED" and my calling services fails with:
Could not locate PropertySource: I/O error on GET request for
"http://localhost:8980/aservice/dev": Connection refused (Connection
refused);
Adding full answer based on comments.
First, you have to specify -p before image name.
docker run -p 8980:8980 my-config-server.
Second, just configuring localhost with host port won't make your my-service container to talk to other container. locahost in container is within itself(not host). You will need to use appropriate docker networking model so both containers can talk to each other.
If you are on Linux, the default is Bridge so you can configure my-config-server container ip docker inspect {containerIp-of-config-server} as your config server endpoint.
Example if your my-config-server ip is 172.17.0.2 then endpoint is - http://172.17.0.2:8980/
spring:
cloud:
config:
uri: http://172.17.0.2:8980
Just follow the docker documentation for little bit more understanding on how networking works.
https://docs.docker.com/network/network-tutorial-standalone/
https://docs.docker.com/v17.09/engine/userguide/networking/
If you want to spin up both containers using docker-compose, then you can link both containers using service name. Just follow Networking in Compose.
I could imagine that the application only listens on localhost, ie 127.0.0.1.
You might want to try setting the property server.address to 0.0.0.0.
Then port 8980 should also be available externally.

Docker on Mac is running but refusing to expose port

Mac here, running Docker Community Edition Version 17.12.0-ce-mac49 (21995).
I have Dockerized a web app with a Dockerfile like so:
FROM openjdk:8
RUN mkdir /opt/myapp
ADD build/libs/myapp.jar /opt/myapp
ADD application.yml /opt/myapp
ADD logback.groovy /opt/myapp
WORKDIR /opt/myapp
EXPOSE 9200
ENTRYPOINT ["java", "-Dspring.config=.", "-jar", "myapp.jar"]
I then build that image like so:
docker build -t myapp .
I then run a container of that image like so:
docker run -it -p 9200:9200 --net="host" --env-file ~/myapp-local.env --name myapp myapp
In the console I see the app start up without any errors, and all seems to be well. Even my metrics publishes (which publish heartbeat and other health metrics every 20 seconds) are printing to the console as I would expect them to. Everything seems to be fine.
Except when I go to run a curl against my app from another terminal/session:
curl -i -H "Content-Type: application/json" -X POST -d '{"username":"heyitsme","password":"12345"}' http://localhost:9200/v1/auth/signIn
curl: (7) Failed to connect to localhost port 9200: Connection refused
Now, if this were a situation where the /v1/auth/signIn path wasn't valid, or if there was something wrong with my request entity/payload, the server would pick up on it and send an error (I assure you; as I can confirm this exact same curl works when I run the server outside of Docker as just a standalone service).
So this is definitely a situation where the curl command can't connect to localhost:9200. Again, when I run my app outside of Docker, that same curl command works perfectly, so I know my app is trying to standup on port 9200.
Any ideas as to what could be going wrong here, or how I could begin troubleshooting?
The way you run your container has 2 conflicting parts:
-p 9200:9200 says: "publish (bind) port 9200 of the container to port 9200 of the host"
--net="host" says: "use the host's networking stack"
According to Docker for Mac - Networking docs / Known limitations, use cases, and workarounds, you should only publish a port:
I want to connect to a container from the Mac
Port forwarding works for localhost; --publish, -p, or -P all work. Ports exposed from Linux are forwarded to the Mac.
Our current recommendation is to publish a port, or to connect from another container. This is what you need to do even on Linux if the container is on an overlay network, not a bridge network, as these are not routed.
The command to run the nginx webserver shown in Getting Started is an example of this.
$ docker run -d -p 80:80 --name webserver nginx
Check that your app bind to 0.0.0.0:9200 and not localhost:9200 or something similar
Problem seems to be in the network mode you are running the container.
Quick test: Login to your container and run the curl cmd there, hopefully it works. That would isolate the problem to request not being forwarded from host to container.
Try running your container on the default bridge network and test.
Refer to this blog for details on the network modes in docker
TLDR; You will need to add an IPtables entry to allow the traffic to enter your container.

Resources