Working with Docker

Docker is a orchestration layer on top of Linux containers. It creates a lightweight work environment like BSD jails, Solaris zones. You need to install set of packages in your ubuntu OS:

1. Create docker images from docker file
docker build -t image1 . ( Docker file is located at ./)

2. List out docker images

docker images

3. changes to images and committing changes

docker run -i -t –name guest image1:latest /bin/bash
apt-get install vim
docker stop guest
docker commit -m “message” -a “author” <container-id of guest> image1:latest

docker rm guest

docker run -i -t –name guest image1:latest /bin/bash

check if installed vim is installed.

dpkg –get-selections |grep vim
3. Update existing image
docker pull mysql
docker stop my-mysql-container
docker rm my-mysql-container
docker run –name=my-mysql-container –restart=always \
-e MYSQL_ROOT_PASSWORD=mypwd -v /my/data/dir:/var/lib/mysql -d mysql

your data should have been stored on -v volumes.

4. List containers

docker ps -a

5. Stop container

docker stop guest

6. start container

docker start guest

7. Aattach a running container, you exited from the session, but container still running

docker attach guest

8. Remove a container

docker rm guest

9. Reomve docker images

docker rmi $(docker images -f “dangling=true” -q)


In general,  egnieers use a script to start a container and share the directories from the host machine. Ex:-


mkdir -p $HOME/$1-shared

docker run –rm -t -i –name $1 -v $HOME/.gitconfig:/root/.gitconfig -e SSH_AUTH_SOCK=$SSH_AUTH_SOCK -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:rw –privileged –net=host -v $HOME/.Xauthority:/root/.Xauthority -v $HOME/$1-shared:/root/shared  image1:latest /bin/bash

option description:

–rm  : remove container when it exit.

–name : name of the container

-i : keep STDIN even container is not attached.

-t : allocate a psudo TTY.

-v :  directory mapping from host to container (sharing of host directories)

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s