-3

I used to use Gin(Golang framework) and deploy docker image to GKE. It was working totally fine.

But the server doesn't respond anymore when I switched Gin to Echo(it is also Golang framework)

I think it is because there is something wrong with port combination(port forwarding).

My echo server code is like below.

func main() {
    e := presentation.Router()

    e.Logger.Fatal(e.Start(":8080")) // listen and serve on :8080
}

and my dockerfile is like below.

FROM alpine:3.9

WORKDIR /app
ADD main /app

ENV PORT 80

EXPOSE 80

CMD ["./main"]

When request reaches to 80 port, it has to render to 8080 port (container port). But it doesn't seem that it is working like above at the moment.

How can I match outer port and inner port??

jub0bs
  • 60,866
  • 25
  • 183
  • 186
anderson
  • 415
  • 1
  • 4
  • 8
  • What host / interface is that listening on? `127.0.0.1/localhost`? Or `0.0.0.0`? If it's the former then that's why it's not working. My guess would be that Gin maybe by default listens on `0.0.0.0` and Echo doesn't? – johnharris85 Aug 14 '19 at 02:50
  • `echo` is listening and serving on port 8080 but you are exposing port 80 of the container, are you doing some port forwarding to direct requests from 80 to 8080, if yes, then please share that code as well, if no, then you need to expose port 8080 of the container. – Praveen Rewar Aug 14 '19 at 03:31
  • @johnharris85 Thank you for answering! Actually gin and echo both are listening on `127.0.0.1/localhost` – anderson Aug 14 '19 at 03:54
  • @PraveenRewar I am not doing anything about port forwarding. I changed `EXPOSE 80` to `EXPOSE 8080` and deployed to GKE but the server still doesn't give us back any response... – anderson Aug 14 '19 at 04:05
  • Are you trying to access the APIs (or anything else) from another container or from the host itself. If you are trying to access it from host then you need to do port mapping as well. `docker run -p 8080:8080 image_name` this will map the 8080 port of the container to the 8080 port of host while running the container. – Praveen Rewar Aug 14 '19 at 04:14
  • @PraveenRewar Yes I am trying to access the API(GKE) from localhost. Should I run `docker run -p 80:8080 image_name`? instead of `8080:8080` because I want to map 80 and 8080(container). and I don't know much about `docker run` command. Because what I used to do is to run `docker build -t image_name` and `gcloud docker -- push image_name` and everything was fine. when I run `docker run -p 80:8080 image_name`, server is up and it doesn't seem that it maps port to another port. – anderson Aug 14 '19 at 04:32
  • `docker run -p 80:8080 image_name` should have done the job. What response are you getting when you hit localhost:80? Are you sure the app is up and running inside the container? – Praveen Rewar Aug 14 '19 at 04:44
  • @PraveenRewar Thank you so much! The server started to respond even after module was deployed! I can not thank you enough! – anderson Aug 14 '19 at 14:40
  • @PraveenRewar would you mind to write it as an answer to be marked as valid? – Albert Sunyer Aug 14 '19 at 15:57
  • tonteki great :) @AlbertSunyer sure I will. – Praveen Rewar Aug 14 '19 at 16:00

1 Answers1

1

Use the command docker run -p 80:8080 image_name for running the container, it will publish the port 8080 of the container and map it with port 80 of the host.

Praveen Rewar
  • 952
  • 1
  • 7
  • 18