Docker-TiPs

1.Install Docker
==================================

For Ubuntu

# apt-get install docker
# whereis docker
(If docker command not any "bin" directories then make soft link
 # ln -sf /usr/bin/docker.io /usr/local/bin/docker  )
Provide docker access to a User
# usermod -aG docker ubadmin
(add group docker if not exist)

For CentOS 

# yum install docker

2.Push Images to a Private Repository
==================================


# docker login
# docker pull cloudofsvk/ubuntu:14.04
# docker run -t -i --name UB-14-Dock ubuntu:14.04 /bin/bash


(Install required packages on container and Run "exit" command to stop the container; e.g; Here Installed Samba,OpenSSH-Server,nmap on Container)
SynTax ---- # docker commit -m="Commit Description" --author="Author Name" :

# docker commit -m="UB-14.04 custom image-ssh-nmap-samba" --author="---SVK---" 78d2254a0130 cloudofsvk/mydocker:smb-ssh-nmap-server

# docker push cloudofsvk/mydocker


3.Pull Images form a Private Repository
==================================

# docker login
# docker pull cloudofsvk/mydocker
# docker images
# docker run -ti --name


4.Convert a Container to Docker Imagefile
==================================


Create a Container install required packages and exit ,After convert the container to Image using following syntax
SynTAx:------  docker commit -a <"Author Name"> -m <"Description/AnyNotes">

# docker commit -a "SVK-Test" -m "SSH with NginX UB12.04" ddf828798ebe test/os:nginx_ssh





5.Rename/Tag a Docker Image
==================================

# docker images
REPOSITORY   TAG      IMAGE ID            CREATED             VIRTUAL SIZE
ub12_04            NginX   0845a8d1350e     18 minutes ago      125.8 MB

#

# docker tag 0845a8d1350e svk/myimages:NGINX_UB_12.04
# docker images
# docker rmi ub12_04:NginX
# docker images

REPOSITORY   TAG      IMAGE ID            CREATED    VIRTUAL SIZE
svk/myimages   NGINX_UB_12.04  0845a8d1350e  20 minutes ago      125.8 MB

#

6.Flatten Your Image (Remove Layesrs)
====================================





Run Image which has a lot of layer

$ docker run -d /bin/bash   
 7423d238b754e6a2c5294xxxx.....
$
(The output shows the ID of the container)
Since the image doesn't really do anything it exits immediately and we're left with a stopped container that is union of all our image layers(I used the -d flag here only so that the ID of container would be displayed).

Export that container and pipe the contents into the docker import command , can turn the container back into an image:

$ docker ps -a
$ docker export 7423d238b | docker import - sample:new_img

3995a1f00b91efb01xxxx.....
$

$ docker history sample:new_img
IMAGE               CREATED             CREATED BY          SIZE
3995a1f00b91        12 seconds ago                          85.18 MB

$

7.Docker Port Forwarding
====================================


Forward default ssh port 22to 2002 and nginx port 80 to 8000

$ docker run -d --name nginx-1 -p 8000:80 -p 2002:22

8.Connect to a Container Running in Background
====================================


Use 'docker exec' to connect to a detached container

$ docker exec -ti /bin/bash