on docker, container, VM

Let's get started with Docker

main-image

Getting started with Docker is very simple, I'm going to give you a very simple recipe to get started quickly, I would first recommend to use DigitalOcean, they provide box with Ubuntu 13.10 and Docker ready for you, so at a very low cost you can start playing with Docker and not have to worry to install anything locally.

If you wish to install Docker locally you can follow this guide : https://www.docker.io/gettingstarted/#h_installation

Ready!? So let's play with Docker then, you can now type docker and you will get list of all available commands.

Let's run echo 'hello world' on a new Ubuntu container

Type the following:
docker run ubuntu /bin/echo hello world

This should output 'hello world'. Just one line?

Docker did all of the following:

  • It downloaded the base image from the docker index
  • it created a new LXC container
  • It allocated a filesystem for it
  • Mounted a read-write layer
  • Allocated a network interface
  • Setup an IP for it, with network address translation
  • And then executed a process in there
  • Captured its output and printed it to you

You can also run an interactive shell session inside the container

docker run -i -t ubuntu /bin/bash

To detach from the container crtl-p + crtl-q

Searching for a docker image: docker search [image name]

Try: docker search ubuntu

Let's do something more exciting now

Run a container and stay attached to the shell session:
docker run -i -t ubuntu /bin/bash

You should see your shell changing to something like: root@b99484200e8t:/#

Type apt-get update
and now install Apache2 : apt-get install -y apache2

Now you can detach (crtl-p + crtl-q)

By default Docker will expose the port 80 of the container to a random port of the host.

So let's list the current containers : docker ps
You should be able to see the port number that is mapped (ie '49158->80'), in your web browser open the IP of your Droplet follow by the mapped port. You should see the Apache running from your docker.

To finish for today, let's now see what happen on our container, let's type docker diff ID_Container (ID_Container you can find it by typing docker ps), with docker diff are able to inspect all the changes made on the container's filesystem.

That's all for this short post, now you can explore the documentation and docker tutorials out there: http://www.docker.io/

 
comments powered by Disqus