RK !

Let's make comprehension easy ...

100%x200

Docker

Author: Romaan, Last Updated: March 1, 2017, 7:21 p.m.

Docker is an open source platform that provides a light weight virtual environment. By light weight environment, I mean, it is NOT a virtual environment like Oracle Virtual box or VMware player or VMware workstation but allows the application and its processes to run in a secluded environment without polluting user's environment with ease of portability. 

Docker Terminology

  • Cgroups - Linux kernel feature that limits, accounts for, and isolates the resource usage of a collection of processes.
  • Container - A runtime instance of a docker image
  • Docker image - An ordered collection of root filesystem
  • Dockerfile - A text document that contains all the commands you would normally execute manually in order to build a Docker image.
  • Registry - A hosted service containing repositories of images which responds to the Registry API

Docker Installation

Assuming you have are using Ubuntu operating system, below are the steps to install Docker:

sudo apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | sudo tee /etc/apt/sources.list.d/docker.list

sudo apt-get update

sudo apt-get install docker-engine

Docker Machine Installation

curl -L https://github.com/docker/machine/releases/download/v0.5.0/docker-machine_linux-amd64.zip >machine.zip && \ unzip machine.zip && \ rm machine.zip && \ sudo mv docker-machine* /usr/local/bin

Once we have the docker installed, we can use the below commands to have a quick look:

Docker basic information

  • sudo docker info # For system wide information on docker
  • sudo docker version # For docker version

Docker images

  • sudo docker search [image name]  # Search for image in repository
  • sudo docker pull [image name]    #Download image
  • sudo docker images            # List installed images
  • sudo docker commit [container ID] [image name]   # Save the state of container
  • sudo docker rmi [image_name]    # Delete the image

One can build her own docker image. In order to build one, create a file named "Dockerfile", mention all the configurations and execute the below command:

  • sudo docker build [tag_name] -f Dockerfile-dev

Docker container management

  • sudo docker run -i -t [image_name] [argument]  # Creates a  container, -t Allocate pseudo terminal, -i Keep STDIN open even if not attached
  • sudo docker run -d -P [image_name] [arguments]  # -d starts container in the background and -P makes any required network ports inside our container to our host
  • sudo docker run -d -p number:number [image_name] [arguments] # -d starts container in background and -p makes the host port to container port
  • sudo docker exec [container_id] [arguments] # Attach to running docker instance
  • sudo docker ps -a -l # Details of all containers
  • sudo docker stop [container_id]  #Stop the container
  • sudo docker rm [container_id] # Remove the container
  • sudo docker stop $(docker ps -a -q) # Stop all containers
  • sudo docker kill $(docker ps -a -q) # Kills all containers
  • sudo docker inspect [image|container] # Prints all the docker meta information in JSON format

Docker networking

  • sudo docker network ls  #Lists the network IDs
  • sudo docker network inspect [network_id]  # Network 

Docker volumes

  • sudo docker volume ls # Lists all the volumes
  • sudo docker inspect [container_name] # Shows the mounted volume information

Docker Compose

One can use docker commands to manage docker containers and images but may get tired typing the commands repeatedly, specially when there are multiple docker instances that needs to be created or destroyed during development or deployed. Docker compose is exactly for this purpose. It can be used to create multiple docker instances. The docker compose looks for docker-compose.yml file where the configurations for creating multiple docker instances are stored.

  • docker-compose up -d    # Starts up all the docker containers specified in docker-compose file
  • docker-compose logs     # Prints the logs from all the containers on to the terminal
  • docker-compose stop -t 1  # Stops all the containers defined by docker-compose 
  • docker-compose rm        # Remove all the containers from memory

A typicla docker-compose file with two images is shown below:

my-container-1:
  image: my-docker-registry:5000/tag
  restart: always
  dns: 172.17.0.1
  ports:
    - "5000"
  environment:
    - PROXY_TO_PORT=5000
    - LISTEN_PORT=5000
    - DNSDOCK_NAME=pes
    - DNSDOCK_IMAGE=sitelink
topbar:
  image: bri-docker-reg:5000/topcon/sitelink-topbar:master-dev
  restart: always
  dns: 172.17.0.1
  ports:
    - "8000:8000"
  environment:
    - DJANGO_SETTINGS_MODULE=topconbar.settings.development
    - DNSDOCK_NAME=topbar
    - DNSDOCK_IMAGE=sitelink

 

Popular Tags:


Related Articles:


Comments: