Vincec's Dimension

Docker Notes

Word count: 452 / Reading time: 3 min
2019/09/29 Share

microservices

Advantage:

  • Easy to build divided into small pieces
  • Can do module
  • Module goes down, whole application dont effect

Disadvantage of virtual machine:

  • Resources hungers

Docker implement

  • Using docker containers on top of virtual machine, docker containers are lightweight alternative virtual machine, no need to pre-allocate the ram and disk
  • Why need virtual machine
    • Docker require linux or unix, if you in PC, need virtual machine
    • No point to run all microservices in host machine, only allocate how much microservies that needed by using virtual machine.

  • Docker container, the runtime instance of Docker Image (which identify what is require for the application)
  • Docker upload to Docker Hub, a git repository for the docker images

  • Problems before Docker (e.g. case: indiana University)
    • Maunal script for create VM
    • Environment not optimized
    • Want Microservice Architecture
    • Need security

Solution, Docker: Docker Data Center(DDC)

Docker Registry

  • A storage component

Docker Images

  • Read only template to create containers
  • Built By Docker Users
  • Stored in Docker Hub

Docker Containers

  • Runtime instance of docker Image
  • Contains everything that needed for the application
  • Built from one or more images

Installation and run example

1
2
3
4
5
6
7
8
9
sudo apt-get update
sudo apt-get remove docker docker-engine docker.io
sudo apt install docker.io
sudo systemctl start docker
sudo systemctl enable docker

sudo service docker start
sudo docker pull centos
sudo docker run -it centos

Docker Compose

With one command and compose multiple containers

Installation

1
2
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

A sample of wordpress docker-compose

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
version: '3.3'

services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress

wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}

Basic Control

1
2
3
4
5
6
7
8
9
10
11
12
cd xxx
# run
sudo docker-compose up -d
# or
sudo docker-compose start

# stop
sudo docker-compose stop

# remove, -v is removing the database volume
sudo docker-compose down
sudo docker-compose down -v

Reference

CATALOG
  1. 1. microservices
  2. 2. Disadvantage of virtual machine:
  3. 3. Docker implement
  4. 4. Docker Registry
  5. 5. Docker Images
  6. 6. Docker Containers
  7. 7. Docker Compose
  • Reference