Skip to content

Instantly share code, notes, and snippets.

@so0k
Last active June 26, 2017 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save so0k/4aff5f31f89c5e3d58f2e71d658df926 to your computer and use it in GitHub Desktop.
Save so0k/4aff5f31f89c5e3d58f2e71d658df926 to your computer and use it in GitHub Desktop.
Docker Singapore - Play with Moby

Play with Moby - Docker Singapore - June 2017

  • Driven by yaml file which defines the assembly we want to create:

    1. kernel (to build bootable vm, stored under /boot) ~> see kernel files info should point to container image which has kernel file (i.e. bzImage) and tar with kernel modules
    2. init: list of images used for init system (unpacked into root filesystem). In case of LinuxKit system this should bring up containerd and system containers For ease of modification runc and containerd images, which just contain these programs are added here rather than bundled into the init container.
    3. onboot list of images run before any other images (can be used to configure one shot settings)
    4. services list of images for long running services which are run with containerd (undefined startup order, thus wait / retry for things such as networking should be built in)
    5. files can be used to add files inline in the config or from external file (default file mode is 0600)

The main use case is to build an assembly that includes containerd to run a set of containers, but the tooling is very generic.

Create self-contained and immutable images

References

Pre-req to demo on AWS:

  • aws cli installed and configured for your AWS Account
  • Docker for Mac

Use Docker-Machine to create a playground instance and ssh into it when ready

# having aws cli pre-configured.. use docker-machine to create new instance (m3.medium does not provide enough memory to run demo)
docker-machine create --driver amazonec2 --amazonec2-region=ap-southeast-1 --amazonec2-instance-type=m3.xlarge aws-02
docker-machine ssh aws-02

Set up all pre-requirements on the AWS Instance (aws cli, moby and linuxkit)

sudo usermod -a -G docker ubuntu

sudo apt install python-pip -y
pip install awscli
aws configure
export AWS_REGION=ap-southeast-1 #required for linuxkit push

git clone https://github.com/linuxkit/linuxkit.git
cd linuxkit/
make
sudo cp bin/{moby,linuxkit} /usr/local/bin/
moby version && linuxkit version

Create S3 bucket and set up AWS roles for aws demo

export S3_BUCKET=demo-linuxkit-images
aws s3 mb s3://${S3_BUCKET} --region ap-southeast-1

curl -Lo vmimport.sh https://raw.githubusercontent.com/ajeetraina/linuxkit/master/projects/aws/vmimport.sh
sed "s/arn:aws:s3:::linuxkit-images/arn:aws:s3:::${S3_BUCKET}" vmimport.sh
sed -i '/#Change linuxkit-images/d' vmimport.sh
chmod +x vmimport.sh
./vmimport.sh

redisOS - demo

moby build -name redisos examples/redis-os.yml
linuxkit run redisos

pstree
netstat -l
nc localhost 6379

AWS - demo

moby build -output raw -name aws3 examples/aws.yml
linuxkit push aws -bucket ${S3_BUCKET}  -timeout 1200 aws.raw
linuxkit run aws aws

Search for the instances created through the AMI specified above: https://ap-southeast-1.console.aws.amazon.com/ec2/v2/home?region=ap-southeast-1#Instances:search=

Open up access to the instance, get public IP and terminate instance...

export INSTANCE_ID=<instance-id>
export SECURITY_GROUP=<security-group_allowing_port_80>
aws ec2 modify-instance-attribute --instance-id $INSTANCE_ID --groups $SECURITY_GROUP
aws ec2 describe-instances --instance-ids $INSTANCE_ID --query "Reservations[].Instances[].PublicIpAddress" --output text

aws ec2 terminate-instances --instance-ids $INSTANCE_ID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment