DockerDocker offical webiste: https://www.docker.com/
Setup DockerPrepare fresh version of CentOS, I am using CentOS 6.7.
Update the yum rep.
> yum update -y
> 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 centosOr
> docker pull centos:centos6
Check which container images are installed:
> docker imagesREPOSITORY 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/bashNote: this creates a container from image (you can see the ContainerID as hostname)
>docker ps>docker ps -a (To List all Containers running/stopped)
>docker start ContainerID
>docker stop ContainerID
>docker rm ContainerID
Re-connect to Container
>docker attach ContainerID
>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/bashTo exit Docker console:
Ctrl+P => Ctrl+Q
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 methodHost 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.
>sudo chmod +x /usr/local/bin/pipework
>sudo bash -c "curl https://raw.githubusercontent.com/jpetazzo/pipework/master/pipework > /usr/local/bin/pipework"
>yum -y install bridge-utils net-tools
If your host server is CentOS 6, then you need to upgrade iproute rpm to support "ip netns" command.
Download RPM from:
>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):
>service network restart
>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
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 firstname.lastname@example.org
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