[Docker] Getting Started with Docker

Foreword:

     Set a flag: I hope to read this book in the two days of the festival and master docker! ! come on

text:

    Linux: Kernel boot, mount root file system to provide user space support

    Docker image Image, equivalent to the root file system, provides programs, libraries, resources, configuration files, and configuration parameters (environment variables, users, anonymous volumes, etc.) prepared for the runtime of the container, and does not contain dynamic data

Docker:

Architecture diagram:

I hope that after reading this blog, everyone can understand this picture, in fact, I just upload the blog


Utilize UnionFS technology, tiered storage:

1. Mirror is a virtual concept and consists of a set of (multi-layer) file systems. It is built layer by layer during construction, and will not be changed again after completion, without affecting each other: delete fake delete

2. It is easier to reuse and customize images. You can use the previous ones to further add, customize your own content, and build new images.

Container related concepts:

1. Image Image and container Container: class and instance, the image is static, the container is a runtime entity, and the essence is a process, running in its own independent namespace (isolation environment, security)

2. Containers can be created, started, stopped, deleted, suspended, etc.; the runtime uses the image as the base layer, and the storage layer on which the current container is created (prepared for runtime read and write, the life cycle is the same as the container)

      A docker container can be understood as a process running in a sandbox. The sandbox contains the resources necessary for the process to run, including the file system, system class library, shell environment, and so on. The sandbox does not run any programs by default. You need to run a process in the sandbox to start a container. This process is the only process of the container, so when the process ends, the container will stop completely. 【source】

3. The container should not write any data to its storage layer (stateless). The write operation should use the data volume or bind the host directory. Read and write in these locations will skip the container storage layer, and the host, network storage Read and write, higher performance stability

4. Data volumes: lifecycle independent of containers

5. Host: A physical or virtual machine that executes Docker daemons and containers

6. Warehouse Registry: save images, Docker Hub (https://hub.docker.com) provides a huge collection of images

7. Machine: Command-line tools that simplify Docker installation, such as VirtualBox, Digital Ocean, Microsoft Azure

Docker Registry: a service for centrally storing and distributing images, which can contain multiple labels, one label for one image

1. Repository: A repository will contain images of different versions of the same software

    1.1 Warehouse name: Two-segment path: User name/software name in DockerRegistry multi-user environment: jwilder/nginx-proxy, not absolute, depends on Docker Registery software or service

2. Label: corresponding to each version of the software, the default latest

3. Specify the specific image through <warehouse name>:<label>: ubuntu: 14:04

4. Public service: registry service that is open to users and allows users to manage: free upload and download of public images

5. Private Docker Registry

Install:

1. Introduction: The Docker system has two programs: the docker server and the docker client.

1.1 The server is a service process that manages all containers.

1.2 The client is the remote controller of the server, which is used to control the server process of docker.

1.3 In most cases, the docker server and client run on one machine. 【source】

Configure the environment before installation: modify the docker configuration file /usr/lib/systemd/system/docker.service, the modification is not an addition

ExecStart=/usr/bin/dockerd --insecure-registry=sz-pg-oam-docker-hub-001.tendcloud.com -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

after modification

systemctl daemon-reload
systemctl restart docker

Basic commands: on the command line

*, run: service docker start, restart docker restart *, stop docker stop *

*. List of command usage methods: docker command --help to query the detailed usage, as explained below

Run 'docker COMMAND --help' for more information on a command

*, docker run  command to run an application in the container, run it into the container

 docker run ubuntu:15.10/bin/echo "Hello world" 
docker binary executable; run run; ubuntu:15.10 image to run; command executed in the /bin/echo "Hello world" container

 docker run -i -t  ubuntu:15.10/bin/bash 

-i: allow interaction with standard input STDIN inside the container; -t: specify a pseudo-terminal or terminal in the new container

You can also run in the background with -d, -P maps the network port number used inside the container to the host used; -p 5000:5000 specifies the port

0.0.0.0:32769->5000/tcp: Docker has opened port 5000 (default Python Flask port) to map to host port 32769, access 32769

mirror

1、搜索镜像:docker search 镜像名字 ,或找Docker Hub

2、下载容器镜像:docker pull ***,移除docker rm *,查看镜像列表:docker images

3、更新镜像:

3.1创建docker run -t -i 镜像 命令

3.2apt-get update更新、exit退出容器、commit提交容器副本

docker commit -m="has update" -a="runoob" e218edb10161 runoob/ubuntu:v2

-m:提交的描述信息;-a:指定镜像作者;e218edb10161:容器ID;runoob/ubuntu:v2:指定要创建的目标镜像名

4、构建镜像:docker build

4.1cat Dockerfile创建Dockerfile文件(一组指令告诉docker如何构建),指令:

FROM,指定使用哪个镜像源

RUN 指令告诉docker 在镜像内执行命令,安装了什么等

4.2docker build -t runoob/centos:6.7 .

-t :指定要创建的目标镜像名

. :Dockerfile 文件所在目录,可以指定Dockerfile 的绝对路径

问题:

1、docker容器中运行hello world的时候报错:

Error response from daemon: shim error: docker-runc not installed on system 

解决方案:

cd /usr/libexec/docker/
sudo ln -s docker-runc-current docker-runc

swarm:集群管理工具


外部用户通过HTTP接口笼统地向集群发出指令,swarm会自动地做一些如负载均衡,保持容器副本数量、伸缩等工作(根据和k8s很像)【源】我修改了docker.service文件,docker起不来了,不清楚是什么原因,以后研究吧

小结:

看菜鸟教程感觉吧不是很复杂,Docker不错的技术

命令大全             资源汇总   指南文档   文档02

http://www.runoob.com/docker/docker-container-connection.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325664889&siteId=291194637