Skip to main content

How to use Docker

Docker
Docker offical webiste: https://www.docker.com/
Setup Docker
Prepare fresh version of CentOS, I am using CentOS 6.7.
Update the yum rep.
> rpm -iUvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
> yum update -y
 
Install Docker
> yum -y install docker-io

Pull some image of container, I am going to use CentOS container.
To pull the latest (CentOs 7)
>  docker pull centos
Or
> docker pull centos:centos6

Check which container images are installed:
> docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              centos6             3bbbf0aca359        2 weeks ago         190.6 MB
centos              latest              ce20c473cd8a        2 weeks ago

Run docker from image:
> docker run -i -t centos:centos6 /bin/bash
Note: this creates a container from image (you can see the ContainerID as hostname)

List containers:
>docker ps
>docker ps -a (To List all Containers running/stopped)

Stop/Start/Remove container:
>docker start ContainerID
>docker stop ContainerID
>docker rm ContainerID
 
Re-connect to Container
>docker attach ContainerID
Or
>docker exe -it ContainerID bash

Run docker container In Background:
> docker run -itd --name cs1 --net=none --hostname=cs1.csteam.net -v /csdata/cs1:/csdata/cs1:rw -v /root/.ssh:/root/.ssh:rw --privileged=true centos:centos6 /bin/bash
To exit Docker console:
Ctrl+P => Ctrl+Q

Networking

For following steps, you need to install pipework script.
#sudo bash -c "curl https://raw.githubusercontent.com/jpetazzo/pipework/master/pipework > /usr/local/bin/pipework"
#sudo chmod +x /usr/local/bin/pipework

If you want to set IP address for container with DHCP. Then you don't need the next section. Setting DHCP settings is easier:
#pipework eth0 ContainerID dhclient
How to expose container with Private IP address from local network: MacVLan method
Host type is easy to setup(-net=host) but the container uses the same network interfaces and can not have their own IP address. That is why, we will use bridged network.
Easier way to setup bridged network is to use "pipework" script that automatizes the procedure.
Install pipework.
>sudo bash -c "curl https://raw.githubusercontent.com/jpetazzo/pipework/master/pipework > /usr/local/bin/pipework"
>sudo chmod +x /usr/local/bin/pipework

Install dependencies:
>yum -y install bridge-utils net-tools
Note:
If your host server is CentOS 6, then you need to upgrade iproute rpm to support "ip netns" command.
Download RPM from:
https://repos.fedorapeople.org/repos/openstack/EOL/openstack-havana/epel-6/iproute-2.6.32-130.el6ost.netns.2.x86_64.rpm
(or iproute-2.6.32-130.el6ost.netns.2.x86_64.rpm)
>rpm -Uvh iproute-2.6.32-130.el6ost.netns.2.x86_64.rpm

Creating bridge(suppose that your Host's Ip=10.40.198.150 on eth0):
>ip addr del 10.40.198.150/24 dev eth0
>ip link add link eth0 dev eth0m type macvlan mode bridge
>ip link set eth0m up
>ip addr add 10.40.198.150/24 dev eth0m
>route add default gw 10.40.198.1
>service network restart
You need to wait for few minutes till the settings get applied.
And, Finally assign $CID container the new private(local) IP :
>pipework eth0 $CID 10.40.198.155/24@10.40.198.1
Done!
you can ping from other local PC, ping 10.40.198.155

How to remove unused virtual network:
>ifconfig br0 down
>brctl delbr br0

Saving Container as Image:
>docker commit $CID myimage:newcs

Comments

Popular posts from this blog

NLP for Uzbek language

    Natural language processing is an essential tool for text mining in data analysis field. In this post, I want to share my approach in developing stemmer for Uzbek language.      Uzbek language is spoken by 27 million people  around the world and there are a lot of textual materials in internet in uzbek language and it is growing. As I was doing my weekend project " FlipUz " (which is news aggregator for Uzbek news sites) I stumbled on a problem of automatic tagging news into different categories. As this requires a good NLP library, I was not able to find one for Uzbek language. That is how I got a motive to develop a stemmer for Uzbek language.       In short,  Stemming  is an algorithm to remove meaningless suffixes at the end, thus showing the core part of the word. For example: rabbits -> rabbit. As Uzbek language is similar to Turkish, I was curious if there is stemmer for Turkish. And I found this: Turkish Stemmer with Snowball.  Their key approach was to u

Three essential things to do while building Hadoop environment

Last year I setup Hadoop environment by using Cloudera manager. (Basically I followed this video tutorial :  http://www.youtube.com/watch?v=CobVqNMiqww ) I used CDH4(cloudera hadoop)  that included HDFS, MapReduce, Hive, ZooKeeper HBase, Flume and other essential components. It also included YARN (MapReduce 2) but it was not stable so I used MapReduce instead. I installed CDH4 on 10 centos nodes, and I set the Flume to collect twitter data, and by using "crontab" I scheduled the indexing the twitter data in Hive. Anyways, I want to share some of my experiences  and challenges that I faced. First, let me give some problem solutions that everyone must had faced while using Hadoop. 1. vm.swappiness warning on hadoop nodes It is easy to get rid of this warning by just simply running this shell command on nodes: >sysctl -w vm.swappiness=0 More details are written on cloudera's site 2. Make sure to synchronize time on all nodes (otherwise it will give error on n

Solving java.lang.ClassNotFoundException problem while exporting Jar file from Eclipse

While running my compiled jar files on hadoop cluster I faced this error many times: Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.conf.Configuration Usually, I don't use maven and attach libraries manually to the project. The libraries that I use are mostly apache's libraries related to hadoop, hive, hbase and etc.. After successful compilation I export the project as a Jar file. I tried to export in many ways but I faced this ClassNotFoundException every time. So I realized that exporting my project with attached jar libraries is not the optimal solution for the problem. Then I found this solution on StackOverflow http://stackoverflow.com/questions/2096283/including-jars-in-classpath-on-commandline-javac-or-apt It describes the way how to add required (dependency) jar files while running the main jar. It is simple! You just put all jars into the same folder where your main jar file is and Run: >java -cp *:. com.kh.demo.RealtimeTFIDF Note