Monday, August 31, 2015

Decoding Docker - Part 1

Having worked with multiple Virtualization platforms, I recently got an interesting opportunity to work with its younger sibling containerization . The  platform of choice was obviously Docker. Getting Docker up and run in an OS of your preference is a simple task, you can straightaway get it done using the instructions here . Interesting part is  getting to play around with it

 Getting it up and running:

Docker can be started as a services or at a tcp port. Starting as a service is pretty straight forward

#service docker start

However, the interesting bit is when you want to run it as a deamon listening to a specific port. This is useful in scenarios when you want to manage the docker engine remotely, say using a windows docker client or using one of the open source GUIs available for docker like Shipyard and

The command to run docker as a deamon listening to a port is

# /usr/bin/docker  -d -H tcp:// -H unix:///var/run/docker.sock &

Here docker will listen at all IPs of the machine at port 4243. If you want to connect to this docker engine from a remote docker client, the following command can be used

#docker -H tcp://<docker engine host>:4243 <commands>

For eg: #docker -H tcp://<docker engine host>:4243 ps

One downside of this method is that there is no inherent authentication mechanisms for remote access

Spin up your containers:

Lets start with pulling an image from the Docker hub, which is  a public repository of Docker images

# docker pull <image name>

Eg: docker pull centos

To list the images in a docker engine, run the following command

#docker images

 Now lets try running the container, the options given below will run the container in the background

#docker run -d -it <image name>

Eg: Docker run -d -it centos

Perfect, this will spin up your container in the docker engine!!

If you want to see the list of containers, you can use the following command

#docker ps


# docker ps -a

The first option will list only the running containers , whereas using the -a option will list all containers, including the running and stopped containers

Now that your container is up and running, you might want to take a look into it. You can connect to the shell of the container using the following command

#docker exec -it  <container name or id>  /bin/bash

Note: The container name/id will be listed while running the "docker ps" commands 

After connecting to the shell of the container, you may want to install few softwares in it, set up your applications etc.Once your container is in a desired state, you might want to commit it locally

#docker commit <container name> <new-image-name>



No comments:

Post a Comment