FGF-College-Work / Forum

:beer: Espaço dedicado a discussões e tira dúvida sobre disciplinas e conteúdo tecnológico.
MIT License
13 stars 4 forks source link

Setting up docker on ubuntu 16.04 #83

Open marcialwushu opened 6 years ago

marcialwushu commented 6 years ago

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:

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