TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Guide to Writing Dockerfiles for Go Web-Apps

102 pointsby alberteinsteinover 7 years ago

9 comments

c2h5ohover 7 years ago
1. Running strip on go binaries is a BAD IDEA: <a href="https:&#x2F;&#x2F;github.com&#x2F;moby&#x2F;moby&#x2F;blob&#x2F;2a95488f7843a773de2b541a47d9b971a635bfff&#x2F;project&#x2F;PACKAGERS.md#stripping-binaries" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;moby&#x2F;moby&#x2F;blob&#x2F;2a95488f7843a773de2b541a47...</a><p>Use -ldflags=&quot;-s -w&quot; instead<p>2. Production build should NOT be running glide install - you want ALL your dependencies vendored, locked and commited to your repo before you build it. Bonus: you can have your Docker image build by CI pipeline and know it&#x27;s going to be exactly like the one you&#x27;ve got locally.<p>3. If you&#x27;re including external resources in your container (upx in this case) via url it&#x27;s common sense to verify GPG signature or, when one isn&#x27;t available, at least file hash<p>4. If your app doesn&#x27;t need things like ca-certs you don&#x27;t need Alpine - you can just use &quot;FROM SCRATCH&quot; to only have the statically linked binary in your container slashing another 50% off the final size of container.
评论 #16310580 未加载
评论 #16311868 未加载
评论 #16313364 未加载
评论 #16310652 未加载
评论 #16310512 未加载
评论 #16314674 未加载
评论 #16311586 未加载
评论 #16313236 未加载
评论 #16312380 未加载
q3kover 7 years ago
I don&#x27;t understand what is the advantage of using Docker in production to run Go. It can already emit static binaries, can contain embedded assets and you can cross-compile for all supported systems using xgo... Ship your binaries, drop them anywhere in the filesystem, run them however you wish and you&#x27;re done.<p>Even for building, a proper build system (like Bazel) is a better tool than building in Docker containers...
评论 #16311289 未加载
评论 #16310387 未加载
评论 #16312579 未加载
评论 #16310348 未加载
评论 #16310424 未加载
评论 #16310309 未加载
评论 #16310320 未加载
评论 #16312820 未加载
tptacekover 7 years ago
Why not use GOOS&#x2F;GOARCH to cross-compile, so you don&#x27;t have to do the compilation step in a virtualized environment? You can build on the host and just copy the resulting binary in like all the rest of your artifacts.
throwaway993472over 7 years ago
I&#x27;ve been using Habitat[1] for shipping all my Go applications. That way I can run the go binaries on whatever kind of infrastructure I need (containers, vms, bare metal). I can mix and match for different environments, or change my mind later without needing to repackage my application or my infrastructure automation.<p>Ultimately at the end of the day I need to work on a team with other operations-minded developers, and shipping them a dockerfile &#x2F; docker container is kind of a spit in the face, so this has been a good solution for me.<p>[1] <a href="https:&#x2F;&#x2F;habitat.sh" rel="nofollow">https:&#x2F;&#x2F;habitat.sh</a>
srameshcover 7 years ago
I&#x27;ve been following this pattern by Kelsey Hightower on his blog <a href="https:&#x2F;&#x2F;medium.com&#x2F;@kelseyhightower&#x2F;optimizing-docker-images-for-static-binaries-b5696e26eb07" rel="nofollow">https:&#x2F;&#x2F;medium.com&#x2F;@kelseyhightower&#x2F;optimizing-docker-images...</a>. I love because the end result is a small base image.
评论 #16311473 未加载
jpsimover 7 years ago
Someone should make a collection of these for all languages. I’d love to see an equivalent for Swift.
collywover 7 years ago
Question, is Docker actually a reliable way of distributing software? I have toyed with it a couple of times and all I ever got was errors about incompatible client and server versions.
评论 #16312103 未加载
czbondover 7 years ago
Related: Anyone have experience with Go and Unikernels? Saw a dead discussion a week ago on unik (<a href="https:&#x2F;&#x2F;github.com&#x2F;solo-io&#x2F;unik" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;solo-io&#x2F;unik</a>)<p>For security purposes, the idea of a unikernel rather than a container has been very interesting. Wanted to use them in a test soon.
评论 #16313411 未加载
sigjuiceover 7 years ago
Why is it a problem to have different versions of Go on the same machine?
评论 #16311661 未加载