Skip to content

Instantly share code, notes, and snippets.

@tarnfeld
Last active August 29, 2015 14:01
Show Gist options
  • Save tarnfeld/693d8f82dcfacd657502 to your computer and use it in GitHub Desktop.
Save tarnfeld/693d8f82dcfacd657502 to your computer and use it in GitHub Desktop.
Lightweight containers with Docker

I was curious to find out if there was a way of maintaing docker's great user experience, while being able to enjoy the simplicity of cgroups on their own.

This has it's benefits, as there's no need to transfer any data in an image that isn't required for your individual service. You can also more easily share packages and installations with the host operating system.

Launch a container with all of the important host stuff mounted

$ sudo docker run -d \
    -v /bin:/bin:ro \
    -v /dev:/dev:ro \
    -v /home:/home:ro \
    -v /lib:/lib:ro \
    -v /lib64:/lib64:ro \
    -v /run:/run:ro \
    -v /sbin:/sbin:ro \
    -v /srv:/srv:ro \
    -v /sys:/sys:ro \
    -v /var:/var:ro \
    --cidfile=/tmp/host-container \
    scratch \
    /bin/bash

Launch two more containers and write different values to the same path

$ export CONTAINER_A=$(sudo docker run -d --volumes-from `cat /tmp/host-container` -t -i scratch /bin/bash -c "mkdir /etc; echo 1 > /etc/foo; cat /etc/foo; sleep 60")
$ export CONTAINER_B=$(sudo docker run -d --volumes-from `cat /tmp/host-container` -t -i scratch /bin/bash -c "mkdir /etc; echo 2 > /etc/foo; cat /etc/foo; sleep 60")

Read the relevent files

$ sudo cat /var/lib/docker/aufs/mnt/$CONTAINER_A/etc/foo
1
$ sudo cat /var/lib/docker/aufs/mnt/$CONTAINER_B/etc/foo
2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment