What is Docker?

What is Docker?

Tudip

15 December 2017

Docker is the operating system level virtualization. It is a tool that reduces the complexity of the communication that required between teams of people while deploying software in the production. As a developer, we can build containers which have different applications installed on them. We can give it to the QA team and they will only need to run a container to replicate the development environment. Now it’s obvious to ask, how does it help? It helps in such a way that there is no need to install all the dependency software and applications by the QA team to test code and so, it will save a lot of time and energy. It also ensures that the working environment is consistent among all the individual involved in the process of developing the application.

Docker Architecture:

The fundamental architecture of Docker is a simple client/server model, with only one executable that acts as both component’s client and server, depending on how you invoke the command. Docker-Architecture

Docker-Client:

You have to use the client to tell the server what to do. A single client can address any number of servers.

Docker-Server:

The server does the ongoing work of running and managing your containers. The Docker daemon can run on any number of servers in the infrastructure.

Docker Installation:

SET UP THE REPOSITORY

  1. Update the apt package index:
    $ sudo apt-get update
  2. Install packages to allow apt to use a repository over HTTPS:
    $ sudo apt-get install \
    apt-transport- https \
    ca-certificates \
    curl \
    software-properties-common
  3. Add Docker’s official GPG key:
    $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  4. To set up the stable repository:
     sudo add-apt-repository \
     "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
     $(lsb_release -cs) \
     stable"

INSTALL DOCKER

$ sudo apt-get update
$ sudo apt-get install docker-ce

What are Docker images?

Docker images consist of one or more filesystem layers and some important metadata that represent all the files required to run a Dockerized application. Every Docker container is based on an image, which provides the basis for everything that you will ever deploy and run with Docker. To launch a container, you can either download the image from Docker hub or create your own Docker image.

What is a Docker container?

Docker container is an instance of the image. You can easily create multiple containers from the same image. A container is a self-contained execution environment that shares the kernel of the host system and which is isolated from other containers in the system.

What is a Dockerfile?

A Dockerfile describes all the steps that are required to create an image. Each line in a Dockerfile creates a new image layer that is stored by Docker. Dockerfile might look something like the one shown here, which will create a container for a Node.js based application:

FROM node:8.9.1
MAINTAINER Jitesh Powankar
# Create app directory
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]

The FROM field will pool the version 8.9.1 of NODE.JS.

FROM node:8.9.1

The MAINTAINER field provides contact information for the Dockerfile’s author, which populates the author field in all resulting images’ metadata:

MAINTAINER Jitesh Powankar

The WORKDIR created the working directory for your application inside the container.

WORKDIR /usr/src/app

The RUN instruction, you can list here all the dependencies that required by your application.

RUN npm install

The CMD instruction, which defines the command that launches the process that you want to run within the container:

CMD ["npm", "start"]

What is a Docker-compose file?

Docker compose is a tool for defining and running multi-container Docker applications. You can compose a file to configure your application’s services. Then, using a single command, you can create and start all the services from your configuration.

Docker commands:

  • Check version
    docker --version
  • Check information
    docker info
  • Downloading image from public registry or docker hub
    docker pull <image-name>
  • Build image
    docker build -t <image_name> .
  • Create container from image
    docker run -d -p 4000:4000 <username>/<image_name>
  • Login to the Docker registry
    docker login
  • Push images to the registry
    docker push <username>/<image_name>
  • Inspecting a Container
    docker inspect <container_id>
  • Inspecting an Image
    docker inspect <image_id>
  • Getting Inside a Running Container
    docker exec -it <container_id> bash
  • Container logs for Docker
    docker logs <container_id>
  • Check active containers
    docker ps
  • Check all available containers on the host
    docker ps -a

search

Blog Categories

Request a quote