Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

💡 An important addition on deploying a Go application in Docker, if net/http is used

Posted on Oct 17 Hey, everybody! 🙌This is a short note article that I can't help but share with the Community, as I ran into this problem myself in my latest wonderful-readme-stats project.So, this will be a very short post, but so important for anyone who wants to deploy a Go application that uses the built-in net/http package, in a Docker container.OK, here we go!I have a helper in my Go project that helps me make a request to the GitHub API and return a response. It is absolutely simple, but saves time as it is used in many places in the code (DRY):You may have noticed that I use strictly defined options to create a custom HTTP client. This is done for a reason! For more information, see this Cloudflare blog post.📝 Note: Building the project for the Docker image is done automatically with GoReleaser. Therefore, I will not cover Dockerfile in detail.Next, I run the finished image as always with this command on the remote server (Ubuntu 22.04):But in the logs, I see the following error when trying to make a request from http.Client to the GitHub API: tls: failed to verify certificate: x509: certificate signed by unknown authority.Wait a minute, why is that? 🤔↑ Table of contentsHere are some useful links that helped me understand the cause of the problem and solve it:Feel free to post your own in the comments.↑ Table of contentsThe solution was so simple that I didn't even believe it! It was enough to add a Docker volume pointing to the directory of the server containing the certificates (/etc/ssl/certs) when starting the container to make it work:❗️ Important: Don't forget to add Docker volume in read-only mode (:ro).And now the container works without errors and displays awesome statistics about the defined repository! 🎉↑ Table of contentsIf you want more articles (like this) on this blog, then post a comment below and subscribe to me. Thanks! 😻And of course, you can help me make developers' lives even better! Just connect to one of my projects as a contributor. It's easy!My projects that need your help (and stars) 👇Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well Confirm For further actions, you may consider blocking this person and/or reporting abuse Brian Bethencourt - Oct 2 Ramakrishnan83 - Sep 24 Zouhair Sahtout - Sep 15 DELI - Sep 15 Once suspended, Koddr will not be able to comment or publish posts until their suspension is removed. Once unsuspended, koddr will be able to comment and publish posts again. Once unpublished, all posts by koddr will become hidden and only accessible to themselves. If koddr is not suspended, they can still re-publish their posts from their dashboard. Note: Once unpublished, this post will become invisible to the public and only accessible to Vic Shóstak. They can still re-publish the post if they are not suspended. Thanks for keeping DEV Community safe. Here is what you can do to flag koddr: koddr consistently posts content that violates DEV Community's code of conduct because it is harassing, offensive or spammy. Unflagging koddr will restore default visibility to their posts. DEV Community — A constructive and inclusive social network for software developers. With you every step of your journey. Built on Forem — the open source software that powers DEV and other inclusive communities.Made with love and Ruby on Rails. DEV Community © 2016 - 2023. We're a place where coders share, stay up-to-date and grow their careers.



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

💡 An important addition on deploying a Go application in Docker, if net/http is used

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×