Our great sponsors
-
examples
Minified application examples with different languages and stacks for DockerSlim (by slimtoolkit)
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
You see this a lot because it's easy and convenient. It's not because it's the best/recommended thing to do. You can use multi-stage builds where you copy everything you need from the build stage to the release stage. It works fine as long as you have a simple application and you know exactly what you need from the build stage. It gets tricky with more complex applications. Another option to try is DockerSlim. It allows you to take those less than ideal container images you see a lot and make them as small as possible. Take a look at this Go application example: https://github.com/docker-slim/examples/blob/master/3rdparty/mux-go-api/Dockerfile
If you want an alternative, lightweight method to create slim Docker images for a Go app, you can check out Ko: https://github.com/google/ko
That's why https://github.com/GoogleContainerTools/distroless is the true perfection.
You can also use https://github.com/breml/rootcerts so you don't even need to copy the files.
Here is a better approach with multi stage builds that does not have the source code https://github.com/codefresh-contrib/golang-sample-app/blob/master/Dockerfile.multistage
Related posts
- How to start a Go project in 2023
- Is there a good example of an open source non-trivial (DB connection, authentication, authorization, data validation, tests, etc...) Go API?
- Which Tools Do You use daily for Golang development?
- Running Virtual Hosts in Apache Docker Container and LetsEncrypt for SSL
- Check all containers for latest version?