Tuesday, February 28, 2017

Docker : failed to get default registry endpoint from daemon, permission denied

If you are getting error while running docker commands by non root user like

Warning: failed to get default registry endpoint from daemon (Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.26/info: dial unix /var/run/docker.sock: connect: permission denied). Using system default: https://index.docker.io/v1/
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.26/images/create?fromImage=alpine&tag=latest: dial unix /var/run/docker.sock: connect: permission denied

Add the non-root-user to group docker by updating /etc/group file or by running following command

usermod -aG docker non-root-user

Docker Basic Commands

Commands which are available to use in Docker to play with images or containers

## Download/Pull an image

docker pull alpine   ## alpine is an images located in local or docker hub repository

## List Docker images available locally

docker images

## Run Docker images

docker run alpine ls -l     #run command will look for image alpine locally if does not exist it will pull from docker hub, creates container and start/run a command in that container

docker run alpine echo "hello from alpine"

docker run alpine /bin/sh

Wait, nothing happened! Is that a bug? Well, no. These interactive shells will exit after running any scripted commands, unless they are run in an interactive terminal - so for this example to not exit, you need to docker run -it alpine /bin/sh

## List running containers

docker ps

## List all containers we ran

docker ps -a

## Run a container with attached tty

docker run -it alpine /bin/sh

This will drop you at /bin/sh shell in container (with tty) where you can run any command as similar to on OS

docker run -it alpine /bin/sh
/ # df -h
Filesystem                Size      Used Available Use% Mounted on
none                     18.1G      1.8G     15.3G  11% /
tmpfs                   496.2M         0    496.2M   0% /dev
tmpfs                   496.2M         0    496.2M   0% /sys/fs/cgroup
                         18.1G      1.8G     15.3G  11% /etc/resolv.conf
                         18.1G      1.8G     15.3G  11% /etc/hostname
                         18.1G      1.8G     15.3G  11% /etc/hosts
shm                      64.0M         0     64.0M   0% /dev/shm
tmpfs                   496.2M         0    496.2M   0% /proc/kcore
tmpfs                   496.2M         0    496.2M   0% /proc/timer_list
tmpfs                   496.2M         0    496.2M   0% /proc/timer_stats
tmpfs                   496.2M         0    496.2M   0% /proc/sched_debug
tmpfs                   496.2M         0    496.2M   0% /sys/firmware

## Inspect any image/container. INSPECT will Return low-level information on a container or image in JSON format

docker inspect alpine

## Remove containers

get the Container ID

docker ps -a

##docker rm container-ID

 docker rm 2db0a4bcb909

## Remove images

get the images IDs

docker images

## docker image rm image-ID   # but make sure containers using this image should be removed first else they will be in unstable state if image is removed

docker image rm 48b5124b2768


  • Images - The file system and configuration of our application which are used to create containers
  • Containers - Running instances of Docker images — containers run the actual applications. A container includes an application and all of its dependencies. It shares the kernel with other containers, and runs as an isolated process in user space on the host OS
  • Docker daemon - The background service running on the host that manages building, running and distributing Docker containers
  • Docker client - The command line tool that allows the user to interact with the Docker daemon
  • Docker Hub - A registry of Docker images. You can think of the registry as a directory of all available Docker images

Docker Installation On Ubuntu 16.04

This post is about installation of Docker on Ubuntu 16.04 (must be 64-bit version)


1) Download Ubuntu 16.04 (http://releases.ubuntu.com/16.04/ubuntu-16.04.2-server-amd64.iso)

2) Install Ubuntu 16.04 (https://help.ubuntu.com/lts/installation-guide/amd64/install.en.pdf)

3) Internet connection available to update and install docker packages and its dependencies

Steps to install Docker:

apt-get update

apt-get install -y --no-install-recommends linux-image-extra-$(uname -r) linux-image-extra-virtual

NOTE : linux-image-extra-* allow docker to use the aufs storage drivers

Ref AUFS -> http://www.thegeekstuff.com/2013/05/linux-aufs/

## Allow apt to use/communicate a repository over HTTPS

apt-get install -y --no-install-recommends apt-transport-https ca-certificates curl software-properties-common

## Add Docker official GPG Key

curl -fsSL https://apt.dockerproject.org/gpg | sudo apt-key add -

## Verify that the key ID is 58118E89F3A912897C070ADBF76221572C52609D

apt-key fingerprint 58118E89F3A912897C070ADBF76221572C52609D

## Add Docker stable repository

add-apt-repository "deb https://apt.dockerproject.org/repo/ubuntu-$(lsb_release -cs) main"

## Install Docker

## update repositories to get the latest packages available to install

apt-get update

## Installing Docker enginer

apt-get -y install docker-engine

## Verify docker is installed correctly

docker run hello-world

It's output should be like

docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete 
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:

For more examples and ideas, visit:

Yay!! You are ready to go with Docker containerization :-)