Skip to content

Instantly share code, notes, and snippets.

@panperla
Last active September 30, 2018 17:19
Show Gist options
  • Save panperla/8fb1e3592c0227cfb5dbc2f7dd9539e8 to your computer and use it in GitHub Desktop.
Save panperla/8fb1e3592c0227cfb5dbc2f7dd9539e8 to your computer and use it in GitHub Desktop.
Installation of docker engine on ubuntu-16.04

Setting up docker on ubuntu 16.04

HOST SECTION

Installation of required packages, adding repository keys, updating repositiory and packages list

sudo apt-get update && sudo apt-get install apt-transport-https ca-certificates curl -y
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list
sudo apt-get update
apt-cache policy docker-engine

In order to be able to use aufs

sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual

Installing docker engine

sudo apt-get install docker-engine

Checking if docker has been installed properly

docker -v
Docker version 1.12.3, build 6b644ec

For the sake of simplicity of deployment it's also good to have docker-compose handy which let's us define a full stack in one file definition. Here is a link to docker-compose repository page: docker-composer project page

Installing docker-compose

 curl -L "https://github.com/docker/compose/releases/download/1.8.1/docker-compose-$(uname -s)-$(uname -m)" > /usr/local/bin/docker-compose
 chmod +x /usr/local/bin/docker-compose 

and checking if everything went well

docker-compose -v
docker-compose version 1.8.1, build 878cff1

Now docker-engine and docker-compose is installed and ready to use.

INTRO docker-compose

This is short intro of what is docker-compose and how to use it. Having docker engine installed we are capable of wrapping any app as a container. By doing this we are platform independet and we can take advantage of continuous integration. In baby steps:

  • Create repository for your app in bitbucket or github
  • Put your app into repository
  • Create Dockerfile which will describe the process of creating docker container
  • Set up hub.docker.com account and create Automated build repository and connect it to your bitbucket/github account
  • Push your app to repository [at this step via webhooks hub.docker.com will get notified there is a change in a repository will download your code and docker file and build your container]
  • When the process of building the container will finish your container is ready to use
  • At this stage we can of course use docker run or docker pull and make use of the container but it's very rare that your app doesn't repend on any additional software
  • At this point we use docker-compose

docker-compose is using yml files to describe the whole stack where your application lives and for example instead of executing each container manually, linking it manually and starting it manually we can simply describe it in docker-compose format and launch it. Let's say our stack consist of nginx and redis and we would like to describe it in docker-compose format:

Create test directory

mkdir testdir

Create in our test dir docker-compose.yml

docker-compose.yml

version: '2'
services: 
  web:
    image: nginx
    ports:
      - "80:80"
    depends_on:
      - redis
  redis:
    image: redis

After you have docker-compose.yml in testdir simply start the whole stack by typing:

docker-compose up 

This command will download nginx and redis-server container, run both containers, bind nginx container on port 80 and expose redis-server to nginx container so nginx can access redis-server.

To stop our stack we simply type:

docker-compose stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment