Docker & Microcontainers

Containers are awesome. Microcontainers are awesome, too. And this is the Docker image having the smallest capacity.

When using Docker, you will quickly realize that the image using to run a project takes a big capacity. A simple image ubuntu took nearly 200MB, but you don’t take full advantage of its available tools. Other images like Node, Go, etc almost run in Ubuntu, debian and only set up more environments to easily deploy. However, downloading a new image takes more time because of its big capacity and it seems to be not necessary at all.

So, I found an empty image :D, except some added metadata by Docker.

docker pull scratch

Therefore, I can say this is the Docker image having the smallest capacity.

Now, we will find out how to deploy an app web with this image

  • I will demo with beego web.
  • I cannot compile app go in this empty image because it has no Go complier. And while using Mac, I cannot compile a Linux library. In reality, we absolutely can cross-compile but I will not mention in this blog. You can refer to here
  • So I need to create an environment to compile and docker build source Go:
docker run --rm -it -v "$GOPATH":/go  -e "GOPATH=/go"  -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):$(which docker) golang bash
  • With the above command, --rm will delete container after exit,-v "$GOPATH":/go share directory GOPATH to container, -e "GOPATH=/go", -v /var/run/docker.sock:/var/run/docker.sock is used to run Docker into container (docker in docker). -v $(which docker):$(which docker) is used to share command docker, golang is image environment to build Go binary and build image, bash to begin Bash session.
  • This time, because I went into container, I cd to project /go/src/
  • Create a Dockerfile with the content below:
# scratch
FROM scratch


# copy binary into image
COPY web web

# copy other necessary files
COPY conf conf
COPY static static
COPY views views


ENTRYPOINT ["/web/web"]
  • Build source by command: go build
  • And link library by:CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o web .
  • Build with docker: docker build -t beego-web .

  • The creating image only takes 17.5MB

  • Then, your laptop had an image, it's is beego-web, the last thing is:

You might also like:

Work with us

Drop us a message if you need any helps from the Dwarves

Let's build something