Unable to expose port using EXPOSE in Dockerfile - docker

I'm trying to expose a JMX port to monitor SpringBoot Application from minikube.
So I added EXPOSE 9010 in Dockerfile and following in deployment.yaml
- containerPort: 9010
- name: JAVA_OPTS
value: "-Dcom.sun.management.jmxremote=true \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.local.only=false \
-Dcom.sun.management.jmxremote.port=9010 \
-Dcom.sun.management.jmxremote.rmi.port=9010 \
-Djava.rmi.server.hostname=127.0.0.1"
however, the port is not getting exposed. Am I missing something here?
Getting below error when trying to port-forward
Handling connection for 9010
E0223 11:48:52.999502 17966 portforward.go:400] an error occurred forwarding 9010 -> 9010: error forwarding port 9010 to pod 4dc803f4d28b82b98dbc0e8fc1448d760f98694e026fb74511b2b8957aa88ef3, uid : exit status 1: 2021/02/23 06:18:52 socat[16604] E connect(5, AF=2 127.0.0.1:9010, 16): Connection refused
Dockerfile:
FROM openjdk:11
WORKDIR /
ADD target/usgagg-service-0.0.1-SNAPSHOT.jar //
EXPOSE 9010
ENTRYPOINT ["java","-Dspring.profiles.active=local","-jar","usgagg-service-0.0.1-SNAPSHOT.jar"]
Note: Springboot server.port is 8080 and I dint create any service to expose 8080 port, I've just added container port in deployment.yaml and it's working fine. I've problem with 9010 only
Update:
Issue is resolved by modifying ENTRYPOINT in Dockerfile to below.
ENTRYPOINT exec java $JAVA_OPTS -Dspring.profiles.active=local -jar /usgagg-service-0.0.1-SNAPSHOT.jar

Related

Podman run kept trying my proxy which is quitted

The error
I have a proxy on localhost:8001, however even when I quit the proxy completely
podman run --log-level=trace \
-p 9000:9000 \
-p 9001:9001 \
minio/minio server /data --console-address ":9001"
Error: initializing source docker://minio/minio:latest: pinging container registry registry-1.docker.io: Get "https://registry-1.docker.io/v2/": proxyconnect tcp: dial tcp 127.0.0.1:8001: connect: connection refused
The env
Macos Monterey 12.3.1.
Docker desktop Version
4.10.0 (82025)
Engine: 20.10.17
Compose: 1.29.2
Credential Helper: v0.6.4
Kubernetes: v1.24.1
Snyk: v1.827.0
Podman version 4.1.1
Trials
I have tried
explicitly setting the proxy in the docker. As in the picture the proxy itself works. ---> trying 8001 does not work
explicitly setting the "manual proxy" and leaving the proxies empty, as described here ---> still trying 8001
Can someone help? Devastated.

why Connection Refused error on simple Docker + nginx configuration?

I have this Dockerfile:
FROM nginx:latest
COPY devops/nginx_proxy.conf /etc/nginx/conf.d/default.conf
EXPOSE 8080
and a devops/nginx_proxy.conf:
server {
listen 8080;
client_max_body_size 32M;
underscores_in_headers on;
}
Running the Dockerfile with docker run -p 8080:80 test and then testing with curl http://localhost/, I see this error:
curl: (7) Failed to connect to localhost port 80: Connection refused
Even more curious, curl http://localhost:8080/ returns this:
curl: (52) Empty reply from server
Why am I getting these errors?
With Docker you can bind containers ports to host ports using the -p option.
General rule
docker run -p HOST_PORT:CONTAINER_PORT
Bind container 8080 port to the 80 of the host
docker run -p 80:8080 test
Ports which are not bound to the host (i.e., -p 80:80 instead of -p 127.0.0.1:80:80) are accessible from the outside
Bind the port limiting the access to localhost
docker run -p 127.0.0.1:80:8080 test

Port 8013 unavailable installing the Data Hub Central warfile in MarkLogic running in a docker container

My docker configuration needs to map ports for external access, but when trying to install the data hub central war file, mlDeploy and mlRedeploy encounter problems, that the ports are unavailable:
Task :mlDeployApp
Creating custom rewriters for staging and job app servers
Loading REST options for staging server
Initializing ExecutorService
Loading default query options from file default.xml
Shutting down ExecutorService
Loading REST options for jobs server
Initializing ExecutorService
Loading traces query options from file traces.xml
Shutting down ExecutorService
Writing traces query options to MarkLogic; port: 8013
Error occurred while loading modules; host: localhost; port: 8013;
cause: java.net.ConnectException: Failed to connect to localhost/127.0.0.1:8013
...
What went wrong:
Execution failed for task ':mlDeployApp'.
Error occurred while loading REST modules: Error occurred while loading modules; host: localhost; port: 8013; cause: java.net.ConnectException: Failed to connect to localhost/127.0.0.1:8013
Docker file contents
FROM store/marklogicdb/marklogic-server:10.0-7-dev-centos
WORKDIR /tmp
EXPOSE 7997-8040
EXPOSE 8080
EXPOSE 9000
CMD /etc/init.d/MarkLogic start && tail -f /dev/null
Original docker run command:
docker run -d --name=marklogic10.0-7_local -p 7997-8040:7997-8040 -p 8080:8080 -p 9000:9000 marklogic-initial-install:10.0-7-dev-centos
Revised docker run command:
docker run -d --name=marklogic10.0-7_local -p 7997-8012:7997-8012 -p 8014-8040:8014-8040 -p 8043:8013 -p 8090:8080 -p 9000:9000 marklogic-initial-install:10.0-7-dev-centos
Note: I originally had the same problem with port 8080 but mapped it to port 8090 which fixed the problem. Doing the same for port 8013 did not work.
The problem was with the installation steps and not the ports.

Go server empty response in Docker container

I have a Go server which something like that. Router is Gorilla MUX
var port string
if port = os.Getenv("PORT"); port == "" {
port = "3000"
}
srv := &http.Server{
Handler: router,
Addr: "localhost:" + port,
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,
}
fmt.Println("Server is running on port " + port)
log.Fatal(srv.ListenAndServe())
Dockerfile is
# Build Go Server
FROM golang:1.14 AS go-build
WORKDIR /app/server
COPY cmd/ ./cmd
COPY internal/ ./internal
COPY go.mod ./
COPY go.sum ./
RUN go build ./cmd/main.go
CMD ["./main"]
I got successful a build. I ran it with following command
docker run -p 3000:3000 baaf0159d0cd
And I got following output. Server is running
Server is running on port 3000
But when I tried to send request with curl I got empty response
>curl localhost:3000
curl: (52) Empty reply from server
Why is server not responding properly? I have another routes which I did not put here and they are not responding correctly too. I am on MacOS by the way.
Don't use localhost (basically an alias to 127.0.0.1) as your server address within a Docker container. If you do this only 'localhost' (i.e. any service within the Docker container's network) can reach it.
Drop the hostname to ensure it can be accessed outside the container:
// Addr: "localhost:" + port, // unreachable outside container
Addr: ":" + port, // i.e. ":3000" - is accessible outside the container

curl (56) Recv failure: Connection reset by peer - when hitting docker container

getting this error while curl the application ip
curl (56) Recv failure: Connection reset by peer - when hitting docker container
Do a small check by running:
docker run --network host -d <image>
if curl works well with this setting, please make sure that:
You're mapping the host port to the container's port correctly:
docker run -p host_port:container_port <image>
Your service application (running in the container) is running on localhost or 0.0.0.0 and not something like 127.0.0.1
I GOT the same error
umesh#ubuntu:~/projects1$ curl -i localhost:49161
curl: (56) Recv failure: Connection reset by peer
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
in my case it was due wrong port no
|---MY Projects--my working folder
--------|Dockerfile ---port defined 8080
--------|index.js-----port defined 3000
--------|package.json
then i was running ::::
docker run -p 49160:8080 -d umesh1/node-web-app1
so as the application was running in port 3000 in index.js it was not able to connect to the application got the error as u were getting
So TO SOLVE THE PROBLEM
deleted the last container/image that was created my worong port
just change the port no of INDEX.JS
|---MY Projects--my working folder
--------|Dockerfile ---port defined 8080
--------|index.js-----port defined 8080
--------|package.json
then build the new image
docker build -t umesh1/node-web-app1 .
running the image in daemon mode with exposed port
docker run -p 49160:8080 -d umesh1/node-web-app1
THUS MY APPLICATION WAS RUNNING without any error listing on port 49161
I have same when bind to port that is not lissened by any service inside container.
So check -p option
-p 9200:9265
-p <port in container>:<port in host os to be binded to>

Resources