Lesson 1: Docker and TurnkeyLinux Tutorial - ano/Docker-on-Turnkeylinux-Core GitHub Wiki

#What you'll need

  • Google Chrome + Simple Docker UI extension
  • TKLBAM (S3/AWS) API Key (will be provided)
  • TurnkeyLinux LAPP
  • Putty

What we'll cover:

  1. An overview of Docker
  2. Pulling an image from the registry
  3. Deploying a Container an Image
  4. Stopping a container
  5. Deleting a container
  6. Removing an image
  7. A look at a simple Docker file
  8. Proposed usage model

#Part 1: Introduction to Docker

Why Use Docker?

Imagine spinning up a fully functioning IMS server with one command

What is Docker?:

Docker, contrary to what its logo depicts, is not a maritime whale job agency, but it is a container technology that allows you to easily package and deploy your applications in a fast, secure and efficient manner. Docker wraps up an application with all the necessary libraries and dependencies it needs to run into a neat self contained object known as a container. Containers can be thought of as lightweight virtual machines that are faster and better than traditional VMs; sorry VMware, the truth hurts.

Thats because these containers ** don't** contain an OS, only the application and the resources needed to run them. All containers that run on a host (the machine on which the docker engine/daemon is installed) use only a single kernel, that of the host. VMs on the other hand require an entire OS installation per VM, and thus a traditional hypervisor runs multiple kernels, one for each VM. This, as you can imagine, is very inefficient.

#Instructions

  1. Open up Google Chrome
  2. Go to the Chrome Store and Install the Simple Docker UI Chrome extension
  3. Use Simple Docker UI extension to do the following

Pull in an Image

Here we'll pull in a docker image from the Docker Registry for use in our Docker Host

  • Got to Settings, put http://159.203.224.179:2375 into the address bar. Click Verify and then Save.
  • Go to Images, search for TurnkeyLinux/LAPP-14.1, click on the star to "pull" the image in to your docker host for usage

Spin Up a Container

  • In Images click on the TurnkeyLinux/LAPP-14.1 image link
  • Click Deploy Container to deploy the container onto the Docker Host, leave the defaults and click RUN. The container will now be available on your Docker Host
  • Click containers to check what containers are running, take note of the ports being mapped. The format is HOST PORT->CONTAINER PORT
  • As an example, To SSH into the container with the port mappings below you would SSH into port 32797
32797->22
32796->2375
32795->12320
32794->12321

Exercise 1: Playing with Docker

  1. Spin up another TurnkeyLinux/LAPP-14.1 container
  2. Putty into it and run psql -v
  3. Stop a Container
  4. Remove a Container
  5. Remove an Image

Exercise 2: Create a File in your container

  1. Spin up a LAPP container
  2. SSH into it
  3. create a file called hello-world.txt
 echo "Hello, my name is YOUR_NAME" | cat > hello.txt

##Extra Exercise Take a look at this Docker file based on *TurnkeyLinux/LAPP-14.1 to see how to build your own docker machines.

https://github.com/ano/TurnkeyLinux-LAPP-and-NodeJS/blob/master/Dockerfile

This one just installs NodeJS and cleans up packages after to keep the size down. Most of the code was copied and pasted from other Docker files found on Github. The last line:

ENTRYPOINT ["/usr/sbin/start.sh"]

An entrypoint is the file that will configure a container to run as an executable on the Docker host. For Turnkeylinux containers the default entry point is /usr/sbin/start.sh

#Part 2: Introduction to TurnkeyLinux and TurnkeyHub/AWS The Turnkey Linux Virtual Appliance Library is a free open source project which has developed a range of Debian based pre-packaged server software appliances (aka virtual appliances) and is founded by engineers of an Israeli startup.

The project currently maintains around 100 virtual appliances, all freely licensed and each a ready-to-use solution optimized for ease of use, with daily automatic security updates and full backup capabilities built in. Each appliance is designed to "just work" with little configuration required. Appliances are optimized for several different virtualization platforms, in addition to two separate builds for installing onto physical media (to non-virtualized hard disk or USB from a hybrid ISO) or onto the Amazon EC2 cloud. They also support Docker, VMWare, Virtualbox, KVM, Promox etc... and have an Amazon Machine Image: provisioned on-demand via TurnKey's "Hub" or the Amazon Elastic Compute Cloud.

##TKLBAM For backup and migration they have a powerful tool called TKLBAM. Basic usage is as follows: On Machine A Backup connect your machine to the hub via your API_KEY

tklbam-init [API_KEY]
tklbam-backup

This will create a small backup image with an ID. Note that backups take only the difference from the Base Image, compress this and then send it to the TurnkeyHub (AMAZON S3)

On Machine B

tklbam-init [API_KEY]
tklbam-restore [BACKUP_ID]

Exercise 3: Linking Docker Container to TurnkeyHub (AWS)

  1. Link your docker image to the TurnkeyHub
tklbam-init [API_Key]
  1. Backup the image with
tklbam-backup

#Whats next?...Combining TKLBAM and Docker (Lesson 2)