Learn about Docker

Docker :

  •      Docker is a application or tool that can package an application and its dependencies in a virtual container that can run on any Linux server.
  •      Package applications into images.
  •      Because Docker containers are so lightweight, a single server can run several containers simultaneously.
  •      The docker daemon process running on the host which manages images and containers.

Docker vs VM :

  •      Virtual machines include the application, the necessary binaries and libraries, and an entire guest operating system — all of which can amount to tens of GBs.
  •      Containers include the application and all of its dependencies –but share the kernel with other containers, running as isolated processes in user space on the host operating system.
  •      Docker containers are not tied to any specific infrastructure, they run on any computer, on any infrastructure, and in any cloud.
    image2017-2-17 9-20-29
    Docker vs Virtual Machine

    Docker Images :

    •      Docker images are the basis of containers.
    •      An Image is an ordered collection of root filesystem changes and the corresponding execution parameters for use within a container runtime.
    •      Images are stored in Docker hub – https://hub.docker.com
    •      Easily distribute the image through Docker Hub.

     Docker Containers : 

    •      A Container is a runtime instance of Docker Image.
    •      Containers are the result of starting an image(run command).
    •      Run many containers with the same image.
    •      A Docker container consists of
      1. A Docker image
      2. Execution environment
      3. A standard set of instructions
    •      Docker Engine manages docker containers.

     Reference :  https://docs.docker.com/engine/understanding-docker/

Installation of Docker :

Docker support various platforms like

  • Mac
  • Windows 10
  • Linux Distributions
  1. Ubuntu
  2. Red Hat Enterprise Linux
  3. CentOS
  4. Fedora
  5. Debian
  6. Oracle Linux
  7. SuSE Linux Enterprise

In this post we learn install Docker in Mac , Windows 10 , Linux Distributions like (Ubuntu,Fedora, Red Hat Enterprise).

 

Install and Run Docker for Mac

Click the link to download the docker toolbox for Mac  –  Docker for Mac

or

Go to official docker site to download docker toolbox for mac  –  official site

  1. Double-click Docker.dmg to open the installer, then drag Moby the whale to the Applications folder.Install Docker app
  2. Double-click Docker.app to start Docker.docker-app-in-apps
  3.  

    You will be asked to authorize Docker.app with your system password after you launch it. Privileged access is needed to install networking components and links to the Docker apps.

    The whale in the top status bar indicates that Docker is running, and accessible from a terminal.

    Whale in menu bar

    If you just installed the app, you also get a success message with suggested next steps and a link to this documentation. Click the whale (whale) in the status bar to dismiss this popup.

    Startup information

  4. Click the whale (whale-x) to get Preferences and other options.Docker context menu
  5. Select About Docker to verify that you have the latest version.

Install Docker for Windows

Click the link to download the docker toolbox for Windows  –  Docker for Windows

  1. Double-click InstallDocker.msi to run the installer.If you haven’t already downloaded the installer (InstallDocker.msi), you can get it here. It typically downloads to your Downloads folder, or you can run it from the recent downloads bar at the bottom of your web browser.
  2. Follow the install wizard to accept the license, authorize the installer, and proceed with the install.You will be asked to authorize Docker.app with your system password during the install process. Privileged access is needed to install networking components, links to the Docker apps, and manage the Hyper-V VMs.
  3. Click Finish on the setup complete dialog to launch Docker. 

installer-finishes.png

Start Docker for Windows

When the installation finishes, Docker starts automatically.

The whale in the status bar indicates that Docker is running, and accessible from a terminal.

If you just installed the app, you also get a popup success message with suggested next steps, and a link to this documentation.

Startup information

When initialization is complete, select About Docker from the notification area icon to verify that you have the latest version.

Get Docker for Ubuntu

OS requirements

To install Docker, you need the 64-bit version of one of these Ubuntu versions:

  • Yakkety 16.10
  • Xenial 16.04 (LTS)
  • Trusty 14.04 (LTS)

Uninstall old versions

Older versions of Docker were called docker or docker-engine. If these are installed, uninstall them:

$ sudo apt-get remove docker docker-engine

It’s OK if apt-get reports that none of these packages are installed.

  1. Update Ubuntu  : apt-get update
  2. Get key from server :   apt-key advkeyserver hkp://ha.pool.sks-keyservers.net:80 —recv-keys 58118E89F3A912897C070ADBF76221572C52609D
  3.  Create list file in apt directory to  add required deb files :
  4.   nano  /etc/apt/sources.list.d/docker.list
  5.     after open add this line – deb https://apt.dockerproject.org/repo ubuntu-xenial main
  6. save and close it.
  7.  Update Ubuntu : apt-get update (it will take the files from https://apt.dockerproject.org/repo )
  8.  Install Docker Engine –  apt-get install docker-engine
  9.  Install Docker Script to docker engine –  wgetqOhttps://get.docker.com/ | sh
  10.  Add user to docker group –  usermodaG docker username
  11.  Start docker service –  systemctl start docker or service docker start
  12. Check docker version – docker -v

Get Docker for Red Hat Enterprise Linux

OS requirements

To install Docker, you need the 64-bit version of RHEL 7.

Uninstall old versions

Older versions of Docker were called docker or docker-engine. If these are installed, uninstall them, along with associated dependencies.

$ sudo yum remove docker \
                  docker-common \
                  container-selinux \
                  docker-selinux \
                  docker-engine

It’s OK if yum reports that none of these packages are installed.

Install the latest version of Docker EE, or go to the next step to install a specific version.

$ sudo yum -y install docker-ee

Start Docker.

$ sudo systemctl start docker

Verify that Docker EE is installed correctly by running the hello-world image.

$ sudo docker run hello-world

Get Docker for Fedora

OS requirements

To install Docker, you need the 64-bit version of one of these Fedora versions:

  • 24
  • 25

Uninstall old versions

Older versions of Docker were called docker or docker-engine. If these are installed, uninstall them, along with associated dependencies.

$ sudo dnf remove docker \
                  docker-common \
                  container-selinux \
                  docker-selinux \
                  docker-engine

It’s OK if dnf reports that none of these packages are installed.

Install the latest version of Docker, or go to the next step to install a specific version.

$ sudo dnf install docker-ce

Start Docker.

$ sudo systemctl start docker

Verify that Docker CE is installed correctly by running the hello-world image.

$ sudo docker run hello-world

Install from a package

If you cannot use Docker’s repository to install Docker, you can download the .rpm file for your release and install it manually. You will need to download a new file each time you want to upgrade Docker.

  1. Go to https://download.docker.com/linux/fedora/7/x86_64/stable/ and download the .rpm file for the Docker version you want to install.

    Note: To install an edge package, change the word stable in the > URL to edge.

  2. Install Docker, changing the path below to the path where you downloaded the Docker package.
    $ sudo dnf -y install /path/to/package.rpm
    
  3. Start Docker.
    $ sudo systemctl start docker
    
  4. Verify that Docker CE is installed correctly by running the hello-world image.
    $ sudo docker run hello-world
    

    This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.

    Basic Docker Commands : 

    •         Pull docker images from docker hub to local repository – docker pull image_name:tag
    •         Push docker image to registry (hub)  –  docker push hubid/image_name:tag
    •         View docker images  –  docker images
    •         View all docker images  –  docker images -a
    •         Rename image  –  docker tag old_image_name:tag new_image_name:tag
    •         View running docker containers  –  docker ps
    •         View all docker containers  –  docker ps -a
    •         Stop running docker container  –  docker stop container_name
    •         Stop all running docker containers  –  docker stop $(docker ps  -q) 
    •         Start stopped container  –  docker start container_name
    •         Remove stopped docker container  –  docker rm container_name
    •         Remove all stopped docker containers  –  docker rm $(docker ps -a -q)
    •         View container details   docker inspect container_name
    •         Remove docker image  –  docker rmi image_name
    •         Remove all docker images  –  docker rmi $(docker images -q)
    •         Save docker image to local repository  –  docker save -o name_to_be_saved.tar image_name  [ NOTE : Docker images are saved in either .tar or .iso ]
    •         Load docker image from local repository to docker engine  –  docker load -i name_of_the_file.tar
    •         Copy contents from local machine to container  –  docker cp path_to_file container_name:path_to_store_file 
    •         Copy contents from container to local machine  –  docker cp container_name:path_to_file path_to_store_file
    •         Run command inside running container  –  docker exec container_name command
    •         View Port bindings in container  –  docker port container_name

    Working with Containers :

    •       Containers start when run docker images – docker run image_name
    •       Docker run commands :

                            -d  =  detach mode run in background 

                            -i   =  interactive mode

                            -name  =  assign a name for container

                            -net  =  connect a container to a network 

                            -t   =  allocate a pseudo tty

                            -p  =  publish a containers port to a host

                            -P  =  publish all exposed port to random ports

     Reference :  https://docs.docker.com/engine/reference/commandline/run/

    Build own Docker image using base image:

          Two methods to update docker image 

                    1) Dockerfile

                    2) Commit

          Dockerfile :

    •                 Create a file called Dockerfile 

                                 FROM  –  It sets the base image for own new image.

                                 RUN  –  It executes any command in a new layer on top of the current image and commit the result.

                                 WORKDIR  –  It sets the work directory for new image.

                                 EXPOSE  –  It informs Docker that the container listen on the specified network port at runtime.

                                 ENTRYPOINT  –  It allows to configure a container that run as an executable.

                                 CMD  –  It provide default for an executing container.

    •                 Sample Dockerfile  format
    • Capture.JPG
    •                 After creating Dockerfile build a image  –  docker build -t new_image_name .

    Reference : https://docs.docker.com/engine/reference/builder/ 

    NOTE : . (dot) in command indicates Dockerfile in current directory. Build the image where the Dockerfile is present. Use -f to define path for Dockerfile. 

    Commit :

    •                  Run container in interactive mode with pseudo tty.image2017-2-16 13-44-23.png
    •      Modify the image whatever want.Force close the container terminal [ Shortcut : ctrl+p+q ] 
    •      Commit a new image with modification  –  docker commit container_name(or)id new_image_name   

                  image2017-2-16 13-45-41.png

    NOTE : Whenever modifying a image must to create a new image otherwise any updation (or) modification is not applied.

    Docker Architecture :

            architecture (3)

    Expose Docker Container to Host :

    •       Exposing container is very important for the host to identify in which port container runs.
    •       -p in docker run command used to expose the ports.
    •       Syntax : docker run -p host_ip:host_port:container_port image_name

    image2017-2-16 13-7-5

    a

    •       This binds port 1500 of the container to port 9650 on 2.12.6.1 of the host machine.
    •       Use Iptables to view the network process  –  iptables -L -n -t nat

    as

    •       Now the request send to host_ip (2.12.6.1) and port (9650) is redirect to container with ip (172.17.0.2) and port (1500).

    NOTE : Containers ip’s are generated by docker engine.

    Docker stages :

             docker-stages.png

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s