How To Deploy a Go Web Application with Docker

While most Go applications compile to a single binary, web applications also ship with templates, assets and configuration files; these can get out of sync and cause faulty deployments.

Docker lets us create a self-contained image with everything our application needs to work. In this tutorial, you will learn how to deploy a Go web application with Docker, and how Docker can help improve your development workflow and deployment process.


In the 3rd step - Running the container, I get an error. It gest stuck at copying the repository I created on my GitHub (go-web-docker). This is the error:
ERROR 0007 Failed to build the application: go build copying /tmp/go-build2900424290/b001/exe/a.out: open mathapp: permission denied

I have already generated a public SSH key on my Linux Machine and authenticated it on the GitHub website, I restarted the whole machine, and I still get the “permission denied” error.

Hi @MilosNj

Does the application build outside the container (in your machine)? It sounds like this is a permission error while building. You could try:

  • Commenting out any USER directive in the Dockerfile to confirm if the problem is with pemissions
  • Adding someting like this to grant write permissions to the tmp folder: RUN chmod -R ugo+rw /tmp

Let me know if this helps!

Hi @TomFern
Thanks, commenting out the USER in the Dockerfile helped with the issue

But now I have a problem when I start the server. It just says it can’t reach the website, “took too long to respond”. I have Webmin installed on my machine, on port 10000, and it works just fine. But the app running on port 8010 doesn’t work. I added the rule to the firewall, and I did the “ufw reload”. On my console it says the app is running but it seems like I can’t reach it on my browser.

You could try starting the container with port mapping:

docker run -it -p 8010:8010

You could also try:

docker run -it --net=host

I’m already using:

docker run -it --rm -p 8010:8010 -v $PWD/src:/go/src/mathapp mathapp-development

No effect.

And --net=host didn’t change anything.

Does it work inside the container? You can use docker exec to get a shell inside it and use curl or wget to see if the application is listening in that port.

I tried it, it doesn’t work even from inside the container. I did curl [ip address from Azure VM] : 8010, and then it says “Failed to connect to [ip address] port 8010: Connection timed out.” I guess there’s a firewall issue? Or I’m using the wrong IP address? But it should be the public IP address of my Azure VM, since that’s where I’m deploying the docker container from? If it’s a firewall issue, I don’t get it how it could be an issue since the port is open.

I just used and it still says port 8010 is closed

I had to go to my Azure platform and allow the port through there. Ufw allow 8010 didn’t work. After allowing the port on Azure, everything works as expected. Thanks.

1 Like