In the previous blog Docker - Part 1, we introduced Docker like what is a docker and why a docker is important? That was enough for the introduction but not adequate for understanding other details. Nowadays docker has become a very useful tool for mobile & web app developers to build and run applications with a combination of all dependencies in one container. It also builds products that let you build and run images as containers on Linux, macOS and Windows. Today we will see further details on Docker. Key Points: Docker images, Docker Volumes, Docker Containers, Dockerfile and Docker registry. Docker Images: Docker images are used to run a container (similar to run a software). An image is like a blueprint of the project files and it's dependencies to run a project. Docker image is an entrenched file, meaning that images cannot be changed. However, containers start from an image, perform the operation within and save a fresh image based on the latest state of the container. Images are constructed with the "build" command and they'll make a container when started with "run". To view images: $ docker images Docker Containers: Containers are a lightweight and portable pack of an environment to run applications further. To transform an image into a container, docker engine takes the image and boots up settings like container name, ID, port, etc. A running container has a currently executing process but when a container has stopped it is known as ‘exited’ in docker. To see what is stopping an image to turn into a container or see a log, you need to run a container in “interactive mode: flag (-it)”. A container is lightweight, separate, executable package of a software which packs together everything needed to run it: system libraries, settings, code, run-time, dependency, system tools. To view running container: $ docker ps To view all(Running + Stopped) container: $ docker ps -a To view log: $ docker run -it <image> Docker Volumes: Containers are stateless, means it does not store any data persistently. After restarting a container or the system; any changes made during the last running session will be wiped out and it gives a clean start (Unless of course, you save it as an image first). But what about persist data practice? Volume is the answer to the above question. When starting any container you can specify a directory as a mount point for volumes - saves changes into running a container. Any changes you made into the container will be written in the given directory path on your host system. The good thing is that the data will remain as it is if the container gets stopped or removed. When a container is exited, any volumes it had been using will persist — hence, if you start a second container it will be able to use all the data that was there in the previous one. To view volumes: $ docker volume ls Dockerfile: “A Dockerfile is a text configured file that is written in a familiar, human-readable. It is a step-by-step script of all the commands that you will need to run to assemble a Docker Image. There are many more commands that you can run while you are building images from written Dockerfile.” Dockerfile installs a configuration of what you need to build a project into an image. You can then execute commands like ADD, CMD, ENTRYPOINT, ENV, EXPOSE, MAINTAINER, RUN, USER, VOLUME, WORKDIR, etc. To build an image from Dockerfile you need to run the command: $ docker build -t <image name> Docker Registry: A Docker registry is a storage and distribution system for Docker images. The same image might have different versions which are identified by tags. The registry, however, permits Docker users to extract images locally, as well as push new images to the registry. By default, Docker engine interacts with DockerHub, Docker's public registry instance. Though it is likely to run on-premise the open-source Docker registry/distribution, and also a commercially backed version called Docker Trusted Registry. There are other public registries available online. To pull an image from Dockerhub: $ docker pull <image name> To pull an image from an on-premises registry $ docker pull my-registry:0000/<image-name> Conclusion Above information and basic commands are that you need to use when you start playing with containers. Now you know how Docker images, Docker Volumes, Docker Containers, Dockerfile and Docker registry work for the developers. 9series is a well known mobile app development company that uses Docker for testing in most of its projects.
Introduction This is just the first Blog in the Series of Blogs we will Write on this topic. If you are a developer or involved in any kind of web & app development and looking for a simple yet effectively functional technology then you are going in the right direction of thinking to deploy the application with the Docker. Docker is nothing but a container which communicates directly with the Linux kernel, hence it is very useful and easy to command in Linux systems. Oh! even Windows and MAC are not left behind to use containers. You may have heard about the vast numbers of developers talking about docker & containers, isolated virtual machine, hypervisors and other DevOps related systems. Today we will talk about the Introduction of Docker. What is a Docker? Docker is a very simple software for containerized applications. The concept of a container is to be a minimum, stateless environment for running a software. A container image is lightweight, separate, executable package of a software which packs together everything needed to run it: system libraries, settings, code, run-time, dependency, system tools. Bypassing all the technical words, we can say that it’s just a tiny package of a virtual machine for running an application which we put in it. It is obvious that everyone is very familiar and have heard about Virtual Machine and Hypervisor. Why a Docker? With Docker we can set-up the environment according to a particular application and process the image building. Docker image is a template (a required libraries) needed to run Docker container and also we need a registry to store images either on local or on web-server. Similarly a web registry (online registry), Docker Hub is a cloud-based registry service allowing you to link to the code repositories, building your images and testing them, manually storing the pushed images, and links to the Docker Cloud so you can deploy images to your hosts. We can also get pre-built images and get up and running in a minimum time than it would take with a normal VM. But, the biggest advantage is creating a homogeneous environment. By, installing Docker, the need to install different dependencies to run your application will no longer be required. Docker is all you need! This being available on all platforms, every developer in your team will be working in the same environment. The same applies to your development, staging and production servers. Now, this is cool. No more “it works on my machine.” Conclusion Here, an endpoint comes to the advantages of using Docker for deploying applications with minimum hassle and an image which is the pack of all required configuration. Stay Tuned to read the next blog in the series!. We will be back with Part II soon!