Wednesday 14 February 2018

Docker on Amazon Ec2 Linux/CentOs

How to install and run Docker on Amazon Ec2 Linux/CentOs

DOCKER: Build, Ship & Run Your Software Anywhere, A lightweight tool which uses container to package up an application with all the requirements and dependencies before shipping the complete container as one package.  Docker is an application that makes it simple and easy to run application processes in a container, which are like virtual machines, which are more portable, more resource-friendly, and more dependent on the host operating system. For a detailed introduction to the different components of a Docker container please visit below link.
https://www.digitalocean.com/community/tutorials/the-docker-ecosystem-an-introduction-to-common-components

Features:
• Use Docker container with any language
• Ship the container wherever you want, be it QA, your team or even the cloud
• Scale up to 1000’s node
• Update with zero downtime

Best practice:
Step 1: Know your Linux release: In my case "4.9.77-31.58.amzn1.x86_64"
  • uname -r
Step 2: Check the update available and you can update a package if required update
  • sudo yum check-update
  • sudo yum update package_name
Step 3: Install Docker:
  • sudo yum -y install docker docker-registry
  • sudo service docker start
  • sudo chkconfig docker on
  • sudo service docker status
Step 4: Verify docker version and know more about docker system.
  • sudo docker --version
  • sudo docker info
Step 5: Add user to docker group to avoid typing sudo every time before docker commands
  • sudo usermod -aG docker $(whoami) (for logged in user)
  • sudo usermod -aG docker username (for any user)
Step 6: Download an image from docker hub(hello-world is known image at docker hub)
  • sudo docker run hello-world
Step 7: Search an docker image in docker hub repository.
  • sudo docker search centos
Step 8: Pull docker image from repository.
  • sudo docker pull centos
Step 9: List all downloaded images.
  • sudo docker images
Step 10: Run docker image.
  • sudo docker run centos
Step 11: Login to docker:.
  • sudo docker attach "docker-id"
[root@c0755c7130fc /]#

Other useful commands:
To view all containers — active and inactive, pass it the -a switch:
  • docker ps -a
To view the latest container you created, pass it the -l switch:
  • docker ps -l
Stopping a running or active container is as simple as typing:
  • docker stop container-id
Starting a stopped container is as simple as typing:
  • docker start container-id















2 comments: