If you are developer, quality analysts or system admin then this tutorial is going to help you. Docker provides solution to many basic use cases for developer, tester and sysadmins. Some of them are:
Use case 1:
If developer has developed an application which runs on java 7 and after some time someone upgraded the version to java 8. Then to run both versions of the applications there is no need to change the host environment to and fro. By using docker, one can run both applications in the containerized environment on their host system without interfering with each other.
Here is another one..
Use case 2:
Developers can give a docker image to tester for QA and other stuff which have all the testing environment already setup in it. Doesn’t it make the life of a tester more easier and happy?
Let’s come back to where we started..
So, What is it?
Docker containers wrap up a piece of software in a complete file system that contains everything it needs to run: code, run time system tools, system libraries – anything you can install on a server.
This guarantees that it will always run the same, regardless of the environment it is running in.
Basically, there simple steps:
Build -> Ship -> Run
VM vs. Docker
This could be the straight question why docker even we can use vm’s (virtual machines) instead of it.The difference is docker containers use kernel resources for its processes instead of creating a guest os on top of host os.The following image describes the difference between a VM and Docker. Instead of a hypervisor with Guest OSes on top, Docker uses a Docker engine and containers on top.
Speed is of course always nice, but being 100 times faster is not only nice, it changes what is possible. This much increase in speed brings whole new possibilities. It is now possible to create throw-away environments.
How can we use docker …
For example you need to deploy a automation testing framework on multiple machine (may be for team people or for testing on different machines). Its very simple way to use the Dockerfile and put your git clone URL in that dockerfile download the packages , dependencies using docekerfile commands (say installing maven, apache , exposing 80 port and java installation) perform all these activities in Dockerfile and then do docker build .By creating Dockerfile you automate your many things which can serve many purposes and make your life easy. Say no to manual,repeatable task and use Dockerfile automation which serves your most of the hurdles.
Another , thing about docker where you can install and start working with docker , so its big yes for windows , linux and mac os. For running docker on windows again require Linux running inside windows, that the design of it.
There are many more things about docker , those are explained below:
Docker Concepts and Interactions
- Host, the machine that is running the containers.
- Image, a hierarchy of files, with meta-data for how to run a container.
- Container, a contained running process, started from an image.
- Registry, a repository of images.
- Volume, storage outside the container.
- Dockerfile, a script for creating images.
Docker interactions with Images
Does command lines interactions bore you, No?
Well you are at the right place. I’ll show you how it interacts with images using command lines. Here are some of the useful commands to play with Docker:
Lets try out basic docker commands :
$ docker images : It shows all the images.
[[email protected] docker-fresh]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 37fa321fe637 About an hour ago 134.7 MB
debian naina 47af6ca8a14a 2 weeks ago 125 MB
hello-world latest 690ed74de00f 6 months ago 960 B
$ docker import : creates an image from a tarball.
$ docker build : creates image from Dockerfile.
Eg. docker build -f Dockerfile
$ docker commit : creates image from a container.
$ docker rmi : removes an image.
$ docker history : list changes of an image.
The Dockerfile supports 13 commands. Some of the commands are used when you build the image and some are used when you run a container from the image. Here is a table of the commands and when they are used.
- FROM – The image the new image will be based on.
- MAINTAINER – Name and email of the maintainer of this image.
- COPY – Copy a file or a directory into the image.
- ADD – Same as COPY, but handle URL:s and unpack tarballs automatically.
- RUN – Run a command inside the container, such as apt-get install.
- ONBUILD – Run commands when building an inherited Dockerfile.
- .dockerignore – Not a command, but it controls what files are added to the build context. Should include .git and other files not needed when building the image.
- CMD – Default command to run when running the container. Can be overridden with command line parameters.
- ENV – Set environment variable in the container.
- EXPOSE – Expose ports from the container. Must be explicitly exposed by the run command to the Host with -p or -P.
- VOLUME – Specify that a directory should be stored outside the union file system. If is not set with docker run -v it will be created in /var/lib/docker/volumes
- ENTRYPOINT – Specify a command that is not overridden by giving a new command with docker run image cmd. It is mostly used to give a default executable and use commands as parameters to it.
Both BUILD and RUN Commands
- USER – Set the user for RUN, CMD and ENTRYPOINT.
- WORKDIR – Sets the working directory for RUN, CMD, ENTRYPOINT, ADD and COPY.