Skip to main content

Docker Basics


When Do You Need to Use Docker?

  • For replicating the environment on your server, while running your code locally on your laptop
  • Experimenting with new things on your laptop without breaking the repositories.
  • Creating a production grade environment on you PC with just simple steps.
  • For instant testing of your application.
  • For Docker CI/CD during numerous development phases (dev/test/QA)
  • For distributing your app’s OS with a team, and as a version control system.

Simple ways to setup docker: -

Route 1 (curl required):
# curl https://get.docker.com | sh

Route 2:

#apt-get update

#apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

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

#apt-key fingerprint 0EBFCD88

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

#apt-get update

#apt-get -y install docker-ce

#docker run hello-world

(Note: Use root to execute Docker commands if you haven’t added your user to the docker group
If you want to add your user to docker group then:
$ sudo usermod -aG docker $USER
After this root access will not be required)


How to use Docker?

  • For checking the number of images on your system, use the following command –
$ docker images

  • For searching an image in the Docker Hub –
$ docker search <image>

  • docker pull – Pulls an image or a repository from a registry
$ docker pull ubuntu

(Note: By default the tag will be “latest” otherwise you need to specify)

  • docker ps – To see the running or stopped docker containers
$ docker ps -a

  • docker run – Creates and starts a new container according to the supplied attributes.
$ docker run  --name containerName –p 8080:80 –it  Ubuntu /bin/bash

(Note: 8080 refers to the host port and 80 refers to the container port.
Refer to https://docs.docker.com/engine/reference/run/ for attribute details and more options)

  • docker attach – It will attach the host terminal to the container terminal
$ docker attach containerName

(Note: exit command inside the container will stop the container and return to the host terminal session but if you want to keep the container running then
Ctrl + (p and q)

  • docker start – Starts one or more stopped containers
$ docker start containerName/Container ID

  • docker stop – Stops one or more running containers
$ docker stop containerName/Container ID

  • docker build – Builds an image form a Docker file

  • docker login – Helps to login to your docker account and then you can push or pull your private or public Docker images.

  • docker push – Pushes an image or a repository to a registry

  • docker export – Exports a container’s filesystem as a tar archive

  • docker exec – Runs a command in a run-time container

  • docker commit – Creates a new image from a container’s changes

How to create your own Docker Image?
·       Create your account on Docker repo site : hub.docker.com

·       Create a Repository with some initial description.

·       User docker commit to save your running container in your local repo.

$ docker commit -m "Apache web server" -a "PrashPlus" 8931afa5aaa6 apacheserver:latest

·       Tag your image with the docker Id and your repository name.

$ docker images

Find your committed image

$ docker tag bb38976d03cf yourhubusername/apacheserver:latest

·       docker push yourhubusername/apacheserver

·       Now your required PC run docker pull and you are ready to go.

$ docker pull yourhubusername/apacheserver

(Feel free to ask for additional commands or any changes required.)

Comments

  1. Big Thanks for this wonderful read. I enjoyed every little bit of reading and I have bookmarked your website to check out new stuff of your blog a must read blog.
    Best Institute for Cloud Computing in Chennai
    Cloud Computing Courses in Chennai

    ReplyDelete
    Replies
    1. You are most welcome, I will try to keep posting articles...

      Delete

Post a Comment

Popular posts from this blog

Ceph Single Node Setup Ubuntu

Single Node Ceph Install A quick guide for installing Ceph on a single node for demo purposes. It almost goes without saying that this is for tire-kickers who just want to test out the software. Ceph is a powerful distributed storage platform with a focus on spreading the failure domain across disks, servers, racks, pods, and datacenters. It doesn’t get a chance to shine if limited to a single node. With that said, let’s get on with it. Inspired from:  http://palmerville.github.io/2016/04/30/single-node-ceph-install.html Hardware This example uses a VMware Workstation 11 VM with 4 disks attached (1 for OS/App, 3 for Storage). Those installing on physical hardware for a more permanent home setup will obviously want to increase the OS disks for redundancy. To get started create a new VM with the following specs: ·         Name: ceph-single-node ·         Type: Linux ·         Version: Ubuntu 16.04.03 (64-bit) ·         Memory: 4GB ·         Disk: 25GB (Dynamic) ·

How to expose your local server to Internet?

As a developer, we always have a wish to expose our work to internet, so that we can show those to our friends or teachers for testing. But, what we choose to use services of public cloud and sometimes it becomes a bit more expensive way for small projects. So, friends I have found a way to expose your localhost services to the internet without port forwarding through the NAT of your ISP. The solution is: NGROK What is ngrok? Ngrok exposes local servers behind NATs and firewalls to the public internet over secure tunnels. How it works You download and run a program on your machine and provide it the port of a network service, usually a web server. It connects to the ngrok cloud service which accepts traffic on a public address and relays that traffic through to the ngrok process running on your machine and then on to the local address you specified. What it's good for Demoing web sites without deploying Building webhook consumers on your dev machine Testing m

Docker Overview

OVERVIEW Docker is the company driving the container movement and the only container platform provider to address every application across the hybrid cloud. Today’s businesses are under pressure to digitally transform but are constrained by existing applications and infrastructure while rationalizing an increasingly diverse portfolio of clouds, datacenters and application architectures. Docker enables true independence between applications and infrastructure and developers and IT ops to unlock their potential and creates a model for better collaboration and innovation. A little intro to LXC: - LXC (LinuX Containers) is a OS-level virtualization technology that allows creation and running of multiple isolated Linux virtual environments (VE) on a single control host. These isolation levels or containers can be used to either sandbox specific applications, or to emulate an entirely new host. LXC uses Linux’s cgroups functionality, which was introduced in version 2.6.24 to