Docker

Docker is an open source container engine, which is written by Golang.

It allows developers to pack app into a lightweight, portable container and deploy on any Linux machine to achieve virtualization. It adopts sandbox mechanism, which has no interface between containers, so that container costs less.

Architecture

Docker uses Cli-Server mode to manage and build container by remote APIs.

1
2
3
Docker        Object-oriented
Container Object
Image Class

Docker Images: The template to build Docker Container.
Docker Container: One or more apps run in container independently.
Docker Client: keep in touch with daemon by command lines and Docker APIs.
Docker Host: a physical or virtual machine to execute Docker daemon and containers.
Docker Registry: a Docker warehouse to store images.
Docker Machine: a command line tool to install Docker in target platform, like VirtualBox, Digital Ocean.

Implements

Web app, Back-end app auto-pack and deployment

Commands

  1. Install docker:
    install docker
    1
    2
    3
    ```
    2. Search commands:
    ```docker

You will see all commands.

Dockerfile

docker build install all setting environments.
commands:
FROM; RUN; ADD; COPY; CMD; EXPOSE; WORKDIR;
MAINTAINER; ENV; ENTRYPOINT; USER; VOLUME

1
2
3
4
5
6
7
8
FROM ubuntu
MAINTAINER xinxin tang
RUN sed -i 's/archive.ubuntu.com/mirrrors.ustc.edu.cn/g' /etc/apt/sources.list
RUN apt-get update
RUN apt-get install -y nginx
COPY index.html /var/www/html
ENTRYPOINT ["/usr/sbin/nginx", "daemon off;"]
EXPOSE 80

Set commands in dockerfile;

Storage - Volume

1
2
docker run -v /usr/xinxin/html nginx
-v: persist storage

Multi-App - docker-compose

set all configurations for packing applications together.
dockerfile;
yaml

commands:
build; command; depends_on; ports; volumes; image;
up; stop; rm; logs; ps