Docker install on Ubuntu 14.04
Docker is an open-source project that makes creating and managing Linux containers really easy. Containers are like extremely lightweight VMs - they allow code to run in isolation from other containers but safely share the machine's resources, all without the overhead of a hypervisor.
In this article, we'll install Docker using Docker-managed release packages as well as Ubuntu managed packages. Using Docker-managed release packages ensures us get the latest release of Docker.
Docker requires a 64-bit installation regardless of our Ubuntu version.
Ubuntu Trusty comes with a 3.13.0 Linux kernel, and a docker.io
package which installs Docker 0.9.1 and all its prerequisites from Ubuntu's repository.
Ubuntu (and Debian) contain a much older KDE3/GNOME2 package called docker
, so the package and the executable are called docker.io
.
To install Docker properly, our kernel must be 3.10 at minimum. The latest 3.10 minor version or a newer maintained version are also acceptable. That's because Kernels older than 3.10 lack some of the features required to run Docker containers. These older versions are known to have bugs which cause data loss and frequently panic under certain conditions.
We can check our current kernel version:
$ uname -r 3.13.0-40-generic
So, we met the Prerequisites!
Let's start.
First, update our package manager. Downloads the package lists from the repositories and "updates" them to get information on the newest versions of packages and their dependencies by synchronizing the package index files fetched from /etc/apt/sources.list
.
$ sudo apt-get update
To install Docker, we need to use :
$ sudo apt-get install docker.io
To make the shell easier to use, we need to create a symlink since /usr/local/bin
is for normal user programs not managed by the distribution package manager. The following command overwrites the link (/usr/local/bin/docker
):
$ sudo ln -sf /usr/bin/docker.io /usr/local/bin/docker
To enable tab-completion of Docker commands in BASH, either restart BASH or:
$ source /etc/bash_completion.d/docker.io
Or
$ source /etc/bash_completion.d/docker
To check if Docker is running:
$ ps aux | grep docker root 8725 0.0 0.2 362736 9352 ? Ssl 10:05 0:00 /usr/bin/docker.io -d
If we want to run docker as root user, we should add a user (in my case, 'k') to the docker group:
$ sudo usermod -aG docker k $ id k uid=1000(k) gid=1000(k) groups=1000(k),4(adm),24(cdrom),27(sudo),30(dip),33(www-data),46(plugdev),108(lpadmin),124(sambashare),1005(svn),131(docker)
We may want to uninstall the Docker if it's already there:
$ sudo apt-get remove docker.io
Then, get the Docker package, and install it from the Docker script:
$ curl -sSL https://get.docker.com/ | sh
or
$ curl -sSL -qo- https://get.docker.com/ | sh
The vertical line pipe character before the sh pipes the output from standard output(-o-) to the terminal to the sh command which says to execute the file that was downloaded in the terminal as a program, assuming that the file that was downloaded first has its permissions set to allow executing the file as a program.
Let's run daemon:
$ sudo docker -d
To verify docker is installed correctly:
$ sudo docker run hello-world
This command downloads a test image and runs it in a container as we can see from the output:
$ sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 535020c3e8ad: Pull complete af340544ed62: Already exists library/hello-world:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security. Digest: sha256:d5fbd996e6562438f7ea5389d7da867fe58e04d581810e230df4cc073271ea52 Status: Downloaded newer image for hello-world:latest Hello from Docker. This message shows that your installation appears to be working correctly.
To see which version of Docker is installed:
$ docker -v Docker version 1.8.1, build d12ea79
To install the latest version, we need to add the Docker repository key to our local keychain:
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9 [sudo] password for k: Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --homedir /tmp/tmp.0gMbMUENwN --no-auto-check-trustdb --trust-model always --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyring /etc/apt/trusted.gpg.d/nagiosinc-ppa.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9 gpg: requesting key A88D21E9 from hkp server keyserver.ubuntu.com gpg: key A88D21E9: "Docker Release Tool (releasedocker)" not changed gpg: Total number processed: 1 gpg: unchanged: 1
Add the Docker repository to our apt sources list:
$ sudo sh -c "echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list" $ cat /etc/apt/sources.list.d/docker.list deb http://get.docker.io/ubuntu docker main
Then, update and install the lxc-docker
package:
$ sudo apt-get update $ sudo apt-get install lxc-docker $ sudo ln -sf /usr/bin/docker /usr/local/bin/docker $ docker -v Docker version 1.9.1, build a34a1d5
We can check if our Docker is installed by running the following command as well:
$ docker info Containers: 12 Images: 77 Server Version: 1.9.1 Storage Driver: aufs Root Dir: /var/lib/docker/aufs Backing Filesystem: extfs Dirs: 101 Dirperm1 Supported: false Execution Driver: native-0.2 Logging Driver: json-file Kernel Version: 3.13.0-40-generic Operating System: Ubuntu 14.04.4 LTS ...
To verify that everything has worked as expected, we can check if Docker downloads the ubuntu image, and then start bash
in a container
:
$ sudo docker run -i -t ubuntu /bin/bash ... Status: Downloaded newer image for ubuntu:latest # exit exit k@laptop:/etc/apt/sources.list.d$
We were able to start bash in a container. And we can check if the image for ubuntu is there:
$ sudo docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu latest 5506de2b643b 4 weeks ago 199.3 MB
We may get the following message when we use docker
without sudo
:
$ docker info 2014/11/21 19:59:03 Get http:///var/run/docker.sock/v1.15/info: dial unix /var/run/docker.sock: permission denied
That's because my user name "k" does not belong "docker" group!
So, let's resolve the issue. First, we need to check if there is docker
group:
k@laptop:~$ cat /etc/group root:x:0: daemon:x:1: bin:x:2: sys:x:3: adm:x:4:syslog,k ... docker:x:131: k@laptop:~$
Ok, docker
is one of the names in the group. So, I need to add my username "k" to the docker
group:
k@laptop:~$ sudo gpasswd -a k docker [sudo] password for k: Adding user k to group docker
Or:
$ sudo usermod -aG docker k
Restart the Docker daemon:
k@laptop:~$ sudo service docker restart
Now, there is no more permission error when we issue docker info
without sudo
:
k@laptop:~$ docker info Containers: 1 Images: 7 Storage Driver: aufs Root Dir: /var/lib/docker/aufs Dirs: 9 Execution Driver: native-0.2 Kernel Version: 3.13.0-35-generic Operating System: Ubuntu 14.04.1 LTS WARNING: No swap limit support
Note: In my case, since I added myself to the group, I had to log out and log back in.
To check the groups I belong:
k@laptop:~$ groups k adm cdrom sudo dip plugdev lpadmin sambashare docker svn
This section is from:
https://docs.docker.com/installation/ubuntulinux/#giving-non-root-access.
Giving non-root access
The docker daemon always runs as the root user, and since Docker version 0.5.2, the docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root, and so, by default, you can access it with sudo.
Starting in version 0.5.3, if you (or your Docker installer) create a Unix group called docker and add users to it, then the docker daemon will make the ownership of the Unix socket read/writable by the docker group when the daemon starts. The docker daemon must always run as the root user, but if you run the docker client as a user in the docker group then you don't need to add sudo to all the client commands. From Docker 0.9.0 you can use the -G flag to specify an alternative group.
Warning: The docker group (or the group specified with the -G flag) is root-equivalent; see Docker Daemon Attack Surface for details.
Example:
# Add the docker group if it doesn't already exist.$ sudo groupadd docker# Add the connected user "${USER}" to the docker group. # Change the user name to match your preferred user. # You may have to logout and log back in again for # this to take effect.
$ sudo gpasswd -a ${USER} docker# Restart the Docker daemon. # If you are in Ubuntu 14.04, use docker.io instead of docker
$ sudo service docker restart
The chkconfig utility is a command-line tool that allows us to specify in which runlevel to start a selected service, as well as to list all available services along with their current setting.
On CentOS, we can simply turn it on to start it automatically:
$ sudo chkconfig docker on
On Ubuntu > 14, the equivalent to chkconfig is sysv-rc-conf. So, we use this instead of chkconfig for Run-level configuration. The sysv-rc-conf an easily communicate and managing with /etc/rc{runlevel}.d/ symlinks.
See the runlevel table below:
We may want to install the sysv-rc-conf package using apt-get command, and then run sysv-rc-conf:
$ sudo apt-get install sysv-rc-conf $ sudo sysv-rc-conf --list acpid anacron apache2 0:off 1:off 2:on 3:on 4:on 5:on 6:off ... docker docker.io ... vmware-works 0:off 2:on 3:on 4:on 6:off x11-common S:on $ sudo sysv-rc-conf docker on $ sudo sysv-rc-conf --list ... docker 2:on 3:on 4:on 5:on docker.io ...
Docker & K8s
- Docker install on Amazon Linux AMI
- Docker install on EC2 Ubuntu 14.04
- Docker container vs Virtual Machine
- Docker install on Ubuntu 14.04
- Docker Hello World Application
- Nginx image - share/copy files, Dockerfile
- Working with Docker images : brief introduction
- Docker image and container via docker commands (search, pull, run, ps, restart, attach, and rm)
- More on docker run command (docker run -it, docker run --rm, etc.)
- Docker Networks - Bridge Driver Network
- Docker Persistent Storage
- File sharing between host and container (docker run -d -p -v)
- Linking containers and volume for datastore
- Dockerfile - Build Docker images automatically I - FROM, MAINTAINER, and build context
- Dockerfile - Build Docker images automatically II - revisiting FROM, MAINTAINER, build context, and caching
- Dockerfile - Build Docker images automatically III - RUN
- Dockerfile - Build Docker images automatically IV - CMD
- Dockerfile - Build Docker images automatically V - WORKDIR, ENV, ADD, and ENTRYPOINT
- Docker - Apache Tomcat
- Docker - NodeJS
- Docker - NodeJS with hostname
- Docker Compose - NodeJS with MongoDB
- Docker - Prometheus and Grafana with Docker-compose
- Docker - StatsD/Graphite/Grafana
- Docker - Deploying a Java EE JBoss/WildFly Application on AWS Elastic Beanstalk Using Docker Containers
- Docker : NodeJS with GCP Kubernetes Engine
- Docker : Jenkins Multibranch Pipeline with Jenkinsfile and Github
- Docker : Jenkins Master and Slave
- Docker - ELK : ElasticSearch, Logstash, and Kibana
- Docker - ELK 7.6 : Elasticsearch on Centos 7
- Docker - ELK 7.6 : Filebeat on Centos 7
- Docker - ELK 7.6 : Logstash on Centos 7
- Docker - ELK 7.6 : Kibana on Centos 7
- Docker - ELK 7.6 : Elastic Stack with Docker Compose
- Docker - Deploy Elastic Cloud on Kubernetes (ECK) via Elasticsearch operator on minikube
- Docker - Deploy Elastic Stack via Helm on minikube
- Docker Compose - A gentle introduction with WordPress
- Docker Compose - MySQL
- MEAN Stack app on Docker containers : micro services
- MEAN Stack app on Docker containers : micro services via docker-compose
- Docker Compose - Hashicorp's Vault and Consul Part A (install vault, unsealing, static secrets, and policies)
- Docker Compose - Hashicorp's Vault and Consul Part B (EaaS, dynamic secrets, leases, and revocation)
- Docker Compose - Hashicorp's Vault and Consul Part C (Consul)
- Docker Compose with two containers - Flask REST API service container and an Apache server container
- Docker compose : Nginx reverse proxy with multiple containers
- Docker & Kubernetes : Envoy - Getting started
- Docker & Kubernetes : Envoy - Front Proxy
- Docker & Kubernetes : Ambassador - Envoy API Gateway on Kubernetes
- Docker Packer
- Docker Cheat Sheet
- Docker Q & A #1
- Kubernetes Q & A - Part I
- Kubernetes Q & A - Part II
- Docker - Run a React app in a docker
- Docker - Run a React app in a docker II (snapshot app with nginx)
- Docker - NodeJS and MySQL app with React in a docker
- Docker - Step by Step NodeJS and MySQL app with React - I
- Installing LAMP via puppet on Docker
- Docker install via Puppet
- Nginx Docker install via Ansible
- Apache Hadoop CDH 5.8 Install with QuickStarts Docker
- Docker - Deploying Flask app to ECS
- Docker Compose - Deploying WordPress to AWS
- Docker - WordPress Deploy to ECS with Docker-Compose (ECS-CLI EC2 type)
- Docker - WordPress Deploy to ECS with Docker-Compose (ECS-CLI Fargate type)
- Docker - ECS Fargate
- Docker - AWS ECS service discovery with Flask and Redis
- Docker & Kubernetes : minikube
- Docker & Kubernetes 2 : minikube Django with Postgres - persistent volume
- Docker & Kubernetes 3 : minikube Django with Redis and Celery
- Docker & Kubernetes 4 : Django with RDS via AWS Kops
- Docker & Kubernetes : Kops on AWS
- Docker & Kubernetes : Ingress controller on AWS with Kops
- Docker & Kubernetes : HashiCorp's Vault and Consul on minikube
- Docker & Kubernetes : HashiCorp's Vault and Consul - Auto-unseal using Transit Secrets Engine
- Docker & Kubernetes : Persistent Volumes & Persistent Volumes Claims - hostPath and annotations
- Docker & Kubernetes : Persistent Volumes - Dynamic volume provisioning
- Docker & Kubernetes : DaemonSet
- Docker & Kubernetes : Secrets
- Docker & Kubernetes : kubectl command
- Docker & Kubernetes : Assign a Kubernetes Pod to a particular node in a Kubernetes cluster
- Docker & Kubernetes : Configure a Pod to Use a ConfigMap
- AWS : EKS (Elastic Container Service for Kubernetes)
- Docker & Kubernetes : Run a React app in a minikube
- Docker & Kubernetes : Minikube install on AWS EC2
- Docker & Kubernetes : Cassandra with a StatefulSet
- Docker & Kubernetes : Terraform and AWS EKS
- Docker & Kubernetes : Pods and Service definitions
- Docker & Kubernetes : Service IP and the Service Type
- Docker & Kubernetes : Kubernetes DNS with Pods and Services
- Docker & Kubernetes : Headless service and discovering pods
- Docker & Kubernetes : Scaling and Updating application
- Docker & Kubernetes : Horizontal pod autoscaler on minikubes
- Docker & Kubernetes : From a monolithic app to micro services on GCP Kubernetes
- Docker & Kubernetes : Rolling updates
- Docker & Kubernetes : Deployments to GKE (Rolling update, Canary and Blue-green deployments)
- Docker & Kubernetes : Slack Chat Bot with NodeJS on GCP Kubernetes
- Docker & Kubernetes : Continuous Delivery with Jenkins Multibranch Pipeline for Dev, Canary, and Production Environments on GCP Kubernetes
- Docker & Kubernetes : NodePort vs LoadBalancer vs Ingress
- Docker & Kubernetes : MongoDB / MongoExpress on Minikube
- Docker & Kubernetes : Load Testing with Locust on GCP Kubernetes
- Docker & Kubernetes : MongoDB with StatefulSets on GCP Kubernetes Engine
- Docker & Kubernetes : Nginx Ingress Controller on Minikube
- Docker & Kubernetes : Setting up Ingress with NGINX Controller on Minikube (Mac)
- Docker & Kubernetes : Nginx Ingress Controller for Dashboard service on Minikube
- Docker & Kubernetes : Nginx Ingress Controller on GCP Kubernetes
- Docker & Kubernetes : Kubernetes Ingress with AWS ALB Ingress Controller in EKS
- Docker & Kubernetes : Setting up a private cluster on GCP Kubernetes
- Docker & Kubernetes : Kubernetes Namespaces (default, kube-public, kube-system) and switching namespaces (kubens)
- Docker & Kubernetes : StatefulSets on minikube
- Docker & Kubernetes : RBAC
- Docker & Kubernetes Service Account, RBAC, and IAM
- Docker & Kubernetes - Kubernetes Service Account, RBAC, IAM with EKS ALB, Part 1
- Docker & Kubernetes : Helm Chart
- Docker & Kubernetes : My first Helm deploy
- Docker & Kubernetes : Readiness and Liveness Probes
- Docker & Kubernetes : Helm chart repository with Github pages
- Docker & Kubernetes : Deploying WordPress and MariaDB with Ingress to Minikube using Helm Chart
- Docker & Kubernetes : Deploying WordPress and MariaDB to AWS using Helm 2 Chart
- Docker & Kubernetes : Deploying WordPress and MariaDB to AWS using Helm 3 Chart
- Docker & Kubernetes : Helm Chart for Node/Express and MySQL with Ingress
- Docker & Kubernetes : Deploy Prometheus and Grafana using Helm and Prometheus Operator - Monitoring Kubernetes node resources out of the box
- Docker & Kubernetes : Deploy Prometheus and Grafana using kube-prometheus-stack Helm Chart
- Docker & Kubernetes : Istio (service mesh) sidecar proxy on GCP Kubernetes
- Docker & Kubernetes : Istio on EKS
- Docker & Kubernetes : Istio on Minikube with AWS EC2 for Bookinfo Application
- Docker & Kubernetes : Deploying .NET Core app to Kubernetes Engine and configuring its traffic managed by Istio (Part I)
- Docker & Kubernetes : Deploying .NET Core app to Kubernetes Engine and configuring its traffic managed by Istio (Part II - Prometheus, Grafana, pin a service, split traffic, and inject faults)
- Docker & Kubernetes : Helm Package Manager with MySQL on GCP Kubernetes Engine
- Docker & Kubernetes : Deploying Memcached on Kubernetes Engine
- Docker & Kubernetes : EKS Control Plane (API server) Metrics with Prometheus
- Docker & Kubernetes : Spinnaker on EKS with Halyard
- Docker & Kubernetes : Continuous Delivery Pipelines with Spinnaker and Kubernetes Engine
- Docker & Kubernetes : Multi-node Local Kubernetes cluster : Kubeadm-dind (docker-in-docker)
- Docker & Kubernetes : Multi-node Local Kubernetes cluster : Kubeadm-kind (k8s-in-docker)
- Docker & Kubernetes : nodeSelector, nodeAffinity, taints/tolerations, pod affinity and anti-affinity - Assigning Pods to Nodes
- Docker & Kubernetes : Jenkins-X on EKS
- Docker & Kubernetes : ArgoCD App of Apps with Heml on Kubernetes
- Docker & Kubernetes : ArgoCD on Kubernetes cluster
- Docker & Kubernetes : GitOps with ArgoCD for Continuous Delivery to Kubernetes clusters (minikube) - guestbook
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization