Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce size of container image #6

Open
squaremo opened this issue Jan 22, 2015 · 9 comments
Open

Reduce size of container image #6

squaremo opened this issue Jan 22, 2015 · 9 comments

Comments

@squaremo
Copy link
Collaborator

At the minute the Dockerfile bases its image on node:0.10, which is notionally reasonable since that's what it needs. However, that base image contains a huge amount of extra guff that's not needed at runtime (it's based itself on debian), and ends up being 700-odd MB.

There are node:*-slim images that are a bit smaller, but I think better still would be to use a container to get the dependencies, then copy those and the runtime out into another container. @errordeveloper has done this elsewhere for IO.js (https://registry.hub.docker.com/u/errordeveloper/iojs-minimal-runtime/)

@binocarlos
Copy link
Owner

Hey - that's a great point - the node dependencies are very minimal (i.e. no node-gyp)

@errordeveloper - could you kindly give me a rough guide to getting a node equivalent to the iojs minimal container or should I just use the iojs one do you think?

I was also thinking that I should base wait-for-weave on busybox as its only a binary mounted in a volume.

@squaremo
Copy link
Collaborator Author

I was also thinking that I should base wait-for-weave on busybox as its only a binary mounted in a volume.

If it's statically linked you could use scratch as the base. That's what the weave router does.

@errordeveloper
Copy link
Collaborator

@errordeveloper - could you kindly give me a rough guide to getting a node equivalent to the iojs minimal container or should I just use the iojs one do you think?

@binocarlos I'd be more then happy if you test out the IO.js container @squaremo referred to. In the meantime I had been making progress on a tooling container that would allow one to rebuild a customised version of that container I used for IO.js. Right now it just gets the tarball of the 1.0.1 release... Please do take this only as a functional prototype, and if you are interested to chat more about building thin runtime-only containers for Node, do ping me over email.

@binocarlos
Copy link
Owner

@errordeveloper that sounds great! It's not that often I find the need for node-gyp or modules that use native extensions (javascript all the things etc) - so a minimal node container is spot on what is needed.

I'll test out powerstrip-weave using iojs-minimal-runtime as a base and will ping you an email about the customized version - thanks!

@binocarlos
Copy link
Owner

Hey guys quick question regarding wait-for-weave - I've changed the binary to be statically linked but am patently learning as I go(lang) so could you check my build command is OK:

CGO_ENABLED=0 go build -a -installsuffix cgo -o stage/wait-for-weave wait-for-weave.go

from the Makefile and largely inspired by this thread

I'm not sure that the -a -installsuffix cgo part is needed (or indeed what it does)...

The code uses the net package via github.com/zettio/weave/net which apparently causes problems with static linking.

However - the above works and I've changed the base image to be scratch which is good news for the image size - next step is trying out the iojs container for powerstrip-weave.

many thanks - sorry for noob questions :-)

@errordeveloper
Copy link
Collaborator

@binocarlos could you show the source code of the wait-for-weave.go program?

@binocarlos
Copy link
Owner

@errordeveloper no probs it lives here

And I've pasted it here:

package main

import (
  "os"
  "os/exec"
  "fmt"
  "github.com/zettio/weave/net"
)

const WEAVE_INTERFACE_NAME = "ethwe"
const WAIT_FOR_SECONDS = 10
const QUIT_IMMEDIATELY_VAR = "WAIT_FOR_WEAVE_QUIT"

/*

  get the cli arguments as an array and remove the
  first element leaving us with the intended entrypoint

  then run that entrypoint attaching stdin, stdout and stderr

*/
func runEntryPoint() {
  entryPoint := make([]string, len(os.Args))
  copy(entryPoint, os.Args)
  // remove blocker from args[0]
  entryPoint = append(entryPoint[:0], entryPoint[1:]...)
  // get and remove the actual command from args[0]
  commandString := entryPoint[0]
  entryPoint = append(entryPoint[:0], entryPoint[1:]...)
  cmd := exec.Command(commandString, entryPoint...)
  cmd.Stdin = os.Stdin
  cmd.Stdout = os.Stdout
  cmd.Stderr = os.Stderr
  cmd.Run()
}

/*

  If the ethwe interface is not found after 10 seconds then write to stderr and exit with non-zero code

*/
func main() {

  /*

    this is so we can run an initial version of this container making its volumes available
    to other containers using --volumes-from

  */
  quitFlag := os.Getenv(QUIT_IMMEDIATELY_VAR)

  if quitFlag == "yes" {
    fmt.Fprintln(os.Stdout, "exiting without waiting because WAIT_FOR_WEAVE_QUIT == yes")
    os.Exit(0)
  }

  if _, err := net.EnsureInterface(WEAVE_INTERFACE_NAME, WAIT_FOR_SECONDS); err != nil {
    a := fmt.Sprint("interface ", WEAVE_INTERFACE_NAME, " not found after ", WAIT_FOR_SECONDS, " seconds")
    fmt.Fprintln(os.Stderr, a)
    os.Exit(1)
  } else {
    runEntryPoint()
  }
}

@binocarlos
Copy link
Owner

Hey guys,

so - I'm having trouble because I realise that there is more than just a node app inside the container - notably (from the Dockerfile) there is:

  • weave bash script
  • curl (to get weave bash script)
  • bash (to run weave bash script)
  • iptables

So - I'm not sure what other dependencies there are regarding the weave bash script doing its magic.

@errordeveloper I have had success using the iojs-minimal-runtime docker image however in powerstrip-debug - you can see the Dockerfile here

That works because there is nothing but a node app inside the container.

Are there any ways to use another image but keep the above dependencies for this adapter?

@binocarlos
Copy link
Owner

Have just found these comments by @rade which are relevant considering this image includes weave

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants