Quantcast
Channel: Webkul Blog
Viewing all articles
Browse latest Browse all 5488

Start your journey with Docker

$
0
0

Today lets talk about docker. As you have read in earlier blog, what exactly docker is ?

Now lets talk about next question, What makes Docker so attractive & how does it work ??

Answer is, 10 Years ago, when virtual machine started at that time we realized that virtual machine shared the same hardware with the base machine, while testing if the virtualized machine goes down then it doesn’t effect our host machine, that was the motto of creating a virtualize machine and there are lots of applications which needs their own environment to run. If basically i say in short, so virtual machine is a resource through which we can create an elusion for app that it has its own environment. But even at that time base machine had enormous load of various virtualized machines, to overcome this situation a new application has been launched named as docker.It is very light weight application and shared the kernel with the base machine in another words it virtualized the environment rather than virtualizing a machine.

The main thing i would like to share with you is we have to install Docker application and then we can run 10-15 containers or more than that on the single base machine without any problem.

Like in our Laptop we cant install 10-15 virtual machines as various applications needs there own environment. So, in your laptop if there is docker installed, then you can work very easily anywhere around the world. It does not have any dependency issue.

one more thing which is important to know is Docker containers can use its own ports like you have two docker containers and both containers are having apache2 application on port 80, so you can run both the containers of apache on different ports at any time.

Docker is very helpful to create an isolated environment.

[DOCKER IN DOCKER’s TERM…]

BUILD ONCE, CONFIGURE ONCE & RUN ANYWHERE……..

There is also one more component in docker is DOCKER INDEX….

You must be thinking what Docker index is ??

Lets talk about the docker index, it is basically a git repository that contains docker containers and all. You can push containers in that repository or pull containers just like git.

These all points make Docker so attractive….

Now lets talk about how does docker work ?

Let me tell you one thing that Docker’s commands are too simple and user friendly. You only just need to understand the flow of its commands.

ok lets install docker in your ubuntu os machine….

First open the terminal with the keyboard shortcut:

 ctrl + Alt + T 
and go to root user with command
sudo -i
 then update your system by typing:
apt-get update
 after updation type the command mentioned below & install the required package:
sudo apt-get install linux-image-generic-lts-trusty

Now check curl if it is not installed then type:

apt-get install curl

Get the latest Docker Package with mentioned command:

curl -sSL https://get.docker.com/ | sh

now verify the Docker if it is installed or not, type:

docker version

if you get 1.8.2 version then its updated docker installed in your system.

[Note: you can get lots of way to installed docker in just few commands but to install updated version of docker, follow the procedure.]

Now lets learn how to run docker…..

firstly you have to download docker’s image like i want to download ubuntu-14.04 image then download it by typing:

docker pull ubuntu:14.04

it will pull the image from docker hub

After pulling it, you can list the images by typing:

docker images

it will show you the complete downloaded images which you have in your system

after that just hit the command to use docker’s image:

docker run -i -t ubuntu:14.04

that command will give you terminal and then you can run or install whatever you want, but remember after installation if you want to save the changes, you have to commit the container and for this you have to open another terminal & from root user type:

docker commit your_container_id your_container-name

now the question arises that how do we get to know container’s id & container’s name ?

you can check your container’s id and name by typing:

docker ps

after committing it, your container is ready to use.

[ Note: Remember one thing that without committing your container don’t exit from it otherwise you’ll loose everything what you have worked on and next time when you will run it, you will get a fresh copy of your previous container, so docker commit is must to save your work in the container”

now if you want to run your container in daemonize mode then you have to hit the command:

docker run -i -d container_name

To stop running container:

docker stop container-id

To remove container:

docker rm container-id

All basic commands are:

  1. attach:-Attach to a running container
  2. build:-Build a container from a Dockerfile
  3. commit:-Create a new image from a container’s changes
  4. cp:-Copy files/folders from the containers filesystem to the host path
  5. diff:-Inspect changes on a container’s filesystem
  6. events:-Get real time events from the server
  7. export:-Stream the contents of a container as a tar archive
  8. history:-Show the history of an image
  9. images:-List images
  10. import:-Create a new filesystem image from the contents of a tarball
  11. info:-Display system-wide information
  12. insert:-Insert a file in an image
  13. inspect:-Return low-level information on a container
  14. kill:-Kill a running container
  15. load:-Load an image from a tar archive
  16. login:-Register or Login to the docker registry server
  17. logs:-Fetch the logs of a container
  18. port:-Lookup the public-facing port which is NAT-ed to PRIVATE_PORT
  19. ps:-List containers
  20. pull:-Pull an image or a repository from the docker registry server
  21. push:-Push an image or a repository to the docker registry server
  22. restart:-Restart a running container
  23. rm:-Remove one or more containers
  24. rmi:-Remove one or more images
  25. run:-Run a command in a new container
  26. save:-Save an image to a tar archive
  27. search:-Search for an image in the docker index
  28. start:-Start a stopped container
  29. stop:-Stop a running container
  30. tag:-Tag an image into a repository
  31. top:-Lookup the running processes of a container
  32. version:-Show the docker version information
  33. wait:-Block until a container stops, then print its exit code


Viewing all articles
Browse latest Browse all 5488

Trending Articles