2

Hey all any help is very much appreciated, I have been stuck on this for a week now...

I am trying to put my golang backend api built by the framework goa inside of a docker container. When I build and run the go binary the server works as intended, I am able to go to my routes and see data being returned. As soon as I put the server in a docker container I get the ERR_CONNECTION_REFUSED / ERR_SOCKET_NOT_CONNECTED and I am very confused on what I am doing wrong.

Here is my Docker file

# Grab hardened go image from artifactory.
FROM golang:1.16.9-alpine 

# Set working directory to be inside the container.
WORKDIR /app
    
COPY . .

# Download all dependencies. 
RUN go build -o main ./cmd

#Expose the port
EXPOSE 8080

# Run the executable
CMD ["./main"]

Here is my netstat result

tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      -                   
tcp6       0      0 :::8080                 :::*                    LISTEN      -  

And lastly, this is when I run the container

[api] 21:43:17 HTTP "Auth" mounted on GET /api/auth
[api] 21:43:17 HTTP "Create" mounted on POST /api/user
[api] 21:43:17 HTTP "ReadByID" mounted on GET /api/user/{id}
[api] 21:43:17 HTTP server listening on "localhost:8080"

Any help is appreciated, let me know if I can provide any more details

  • 2
    `HTTP server listening on "localhost:8080"` In addition to exposing the port from the host to the docker container, you *also* have to listen to 0.0.0.0 (or your docker container's IP, but 0.0.0.0 makes more sense as docker Ip will not be constant). If you only listen to localhost, the host will attempt to forward traffic, but the container end won't be listening anywhere but its (own dedicated) localhost. – erik258 Dec 23 '21 at 23:00
  • @DanielFarrell This seems to have solved my current issue, thank you! – Skyler Seifert Dec 23 '21 at 23:42

0 Answers0