Docker : Installation, Pull and Run a Container from Docker HUB

Installation of Docker is pretty straightforward. In this article we will be focusing on Linux installation for docker. Do check below links for docker installation in other OS

-Install Docker on Ubuntu

-Install Docker on Windows

-Install Docker on MacOS

-Install Docker on Raspbian (Raspberry PI)

Alternatively, for Linux/Raspberry Pi just run this command and you are good to go

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

docker-install

Follow the below instructions to install docker on linux machine [OPTIONAL]

1. Add GPG keys for official docker repo

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

2. Add docker repo to apt sources

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

3. Update package database

sudo apt-get update

4. Install Docker

sudo apt-get install -y docker-ce

Moreover you can check the full installation HERE


Basic Commands to check Docker Installation

Check weather docker is installed and running (to quit CTRL+C)

sudo systemctl status docker

List Docker (list of docker commands, also management command-since docker 2017)

sudo docker

Docker Version (returns the version of client and server (engine/daemon/service)

sudo docker version

Docker Info (returns details about our configuration and setup for our engine)

sudo docker info

Docker Daemon Start/Stop

Docker has 2 components :
1. Docker Daemon (Engine) : This is the core of Docker which runs in the background
2. Docker CLI (Client) : Docker component with which user interacts

docker-cli-daemon

Both these components communicate with each other using REST API’s on Port number – 2376

START Docker Daemon

sudo service docker start

STOP Docker Daemon

sudo service docker stop

Running a Container

Before running a Container we need to have a Docker Image (as container is a runtime instance of docker image), we can not run a container without having a Docker Image , cause that will not make any sense.

So here are some Commands for for Docker Images

View Docker Images present on our computer

sudo docker images
sudo docker images ls

View details of Docker Image present

sudo docker inspect ImageID

Delete Docker image from System

sudo docker rmi ImageID

So now that we know about docker images lets see how to run them, and no worries if you don’t have any image in you system (we have that covered)


Docker RUN command

Here is the most important docker command which is used to Run Images and if that image is not present locally on you system then docker run will download it from dockerhub and run it

sudo docker run -it Image

We can attach additional parameter as -d (for detach mode) , -p (to map port of docker and host)

To give it a try, run ubuntu image (if its not present locally, which i guess not, then it will download and run that command)

sudo docker run centos –it /bin/bash

This command will download the centOS image from docker hub and start an interactive session at /bin/bash

Alternatively, if you want only to pull image and not run it, you can use the below command. Also this command can also be used when your local system has a outdated image and you want to update you local copy with updated copy.

sudo docker pull centos

Thats all for this session, in next tutorial we will explore more into containers.

Leave a Reply

Your email address will not be published. Required fields are marked *