How to expose and run/serve a GO web application running within a Docker Container

Goal Set up a test environment to replicate a web server using Docker running a GO application

What I have done so far

  • I have a Dockerfile as below, pretty straightforward
FROM golang:alpine as unwindtest


COPY . /app/

RUN ls -al

RUN go install -v
RUN go build -v .
  • After building the Dockerfile, with the command as
docker build -t unwindtest:$BUILD_NUMBER .
  • Run the image and run the binaries from within the container
docker run --env-file ./env.list --rm -it -p 8010:8010 unwindtest:$BUILD_NUMBER

/app # /go/bin/<name of binary/app>
  • I expose the port as change the nfw settings with sudo ufw allow 8010/tcp

  • docker ps -a also shows something as below

290c17f5d54b        unwindtest:0.0.2    "/bin/sh"           13 days ago         Up 13 days>8010/tcp   affectionate_mendel
  • Are we listening to the port
root@whatever# netstat -plant | grep 8010
tcp6       0      0 :::8010                 :::*                    LISTEN      136450/docker-proxy
  • Now problem is I go to the port for the Docker DO droplet and look for the port but neither can I curl or see anything here


How do I expose and run this GO application on the localhost as http:\\<ip>:port , or simply put am I missing any steps here?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi there,

I think that with the current Dockerfile you are just building the executable but not running it.

I believe that you should add a CMD command at the end:

# Run the executable
CMD ["./your-go-app"]

That way when you run the container it will actually start the Go application as well.

Besides that, all the other things that you’ve shared look good.

Let me know how it goes! Regards, Bobby