https://github.com/hesion3d/slimage
Make slim docker image for golang applications.
https://github.com/hesion3d/slimage
Last synced: 3 months ago
JSON representation
Make slim docker image for golang applications.
- Host: GitHub
- URL: https://github.com/hesion3d/slimage
- Owner: hesion3d
- License: apache-2.0
- Created: 2016-10-25T08:23:03.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-12-30T05:16:18.000Z (about 8 years ago)
- Last Synced: 2024-08-03T11:03:10.907Z (7 months ago)
- Language: Shell
- Homepage:
- Size: 21.5 KB
- Stars: 49
- Watchers: 6
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
#slimage#
中文版请见 [README.zh_CN.md](https://github.com/hesion3d/slimage/blob/master/README.zh_CN.md)
Make slim docker image for golang applications.
##background##
[Docker](https://www.docker.com/) makes deployment of server-side applications much easier.
And to build docker image, the simplest way is to depends on some Golang image and ADD your code in. However, there are two main drawbacks in this approach.
- The size is usauly ~500MB;
- The source code is also delivered with the binary.There are already lots of creative ways to build a minified docker image on the web. Slimage is a simple commandline tool inspired by [Nick Gauthier](https://blog.codeship.com/building-minimal-docker-containers-for-go-applications/) and [Adriaan](http://blog.xebia.com/create-the-smallest-possible-docker-container/)'s idea with slight modification. With slimage, you could build go application w/o Cgo support at ~25MB (including some basic linux commandline binaries for debugging).
slimage works in Bash. And we also provide a port for windows commandline.
##usage##
linux/mingw or mac:
```
$ git clone https://github.com/hesion3d/slimage.git
$ cd slimage
slimage$ export GOPATH=`pwd`/demo
slimage$ ./run.sh -f demo-config.sh -l min -n hello-slimage
Prepare for building...
Building src...
Analyzing ELF files...
Building...
Sending build context to Docker daemon 8.127 MB
Step 1 : FROM scratch
--->
Step 2 : COPY . /
---> Using cache
---> 8c143d09beb3
Step 3 : ENTRYPOINT /opt/bin/hello-slimage --server_ip=0.0.0.0
---> Using cache
---> 422adde5b9af
Successfully built 422adde5b9afslimage$ docker run --rm -p 8080:80 hello-slimage
```or in windows:
```
run.bat -f demo-config.sh -l min -n hello-slimage
```##insides##
Instead of building docker image in docker, as described in most of the articles on the web, slimage build go source code from the image. Basically, we
1. find out all the dependencies of the binaries (ELF format) to pack
2. make the directory tree
3. copy the tree to temporary dir with a DOCKERFILE
4. exit from the docker container and build the image outside.##reference##
1. [Building Minimum Docker Containers for Go Applications](https://blog.codeship.com/building-minimal-docker-containers-for-go-applications/).
2. [Create the Smallest Possible Docker Container](http://blog.xebia.com/create-the-smallest-possible-docker-container/).