docker study notes (a) docker entry

table of Contents

basic concepts

docker engine

docker architecture

Installation docker

docker commonly used commands


Docker is an application container engine open source, which is based on  the Go language  and protocol compliance Apache2.0 open source.

Docker allows developers to package their applications and dependencies to a lightweight portable container, and then posted to any popular Linux machine, can be virtualized.

Before there docker, we generally use virtualization technology to deploy multiple projects on a single PC, containers and virtual machines have similar isolation and resource allocation advantages, but different functions, can be seen from the figure, the operation of container virtualization system, not just hardware, virtual machine container relatively easier portability.

    

Code corresponding to the container and depend packaged together to form a whole run. A plurality of containers can be run on the same computer, and share the operating system kernel and other containers, each running as an isolated process in user space, can be reassigned when creating the corresponding container space required space smaller than VM

Virtual machine (VM) is a server as multiple servers to use. Hypervisor allows multiple VM running on a single computer. Each VM contains the operating system, applications, necessary binaries and a few GB of system. In the beginning of creation need to allocate for the virtual machine enough memory space

basic concepts

Docker contains three basic concepts:

Container (container):

Code and its packaging container is a standard unit for all software dependencies, so the application can be a machine running quickly and reliably from the environment to another environment. Docker containers are lightweight, stand-alone, executable software package that contains all the code, system tools, system libraries and configuration files required to run applications and so on.

A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.

Image (镜像):

An image is a read-only template with instructions for creating a Docker container. Often, an image is based on another image, with some additional customization. 

Mirroring is running in a container on a docker engine, so the image is the equivalent of a template container that contains all the codes, environmental parameters, configuration files needed to run and other containers

Image Container and relationships:

Container images become containers at runtime and in the case of Docker containers - images become containers when they run on Docker Engine

Repository (warehouse)

Storage Mirroring place, you can have a docker official repository, also has Ali cloud, they can also build their own warehouses mirror, similar to the maven repository

Simple to understand: the warehouse is used to store images of the place, we obtain from the warehouse to the mirror, and then to produce a vessel through a mirror, you can specify the parameters generate a different container object you want in the build process

docker engine

Docker Engine consists of the following major components:

  • The server is running a long-term program, called daemon process (dockerd command).

  • REST API, which specifies the program can be used to communicate with a daemon (server), and instructs the interface operation thereof.

  • Command Line Interface (CLI) client (we often say docker command).

 

CLI use Docker REST API to control Docker daemon via script or CLI command or directly interact with Docker daemon.

docker architecture

Docker using a client - server architecture. After Docker clients to communicate with Docker daemon daemon, the daemon accepts client orders, according to the command execution to build, run and distribute the work Docker containers, and interact with the registry (in fact docker mirrored warehouse).

When using the docker pull or docker run commands from the configuration of the desired image docker warehouse download. When using the docker Push command, it will be pushed to the image repository docker configuration.

Installation docker

First to root sudo -i

1. If you have installed docker, uninstall

[root@10 ~]# sudo yum remove docker docker-client  docker-client-latest  docker-common  docker-latest  docker-latest-logrotate docker-logrotate docker-engine        

2. Download docker dependent

[root@10 ~]# sudo yum install -y yum-utils device-mapper-persistent-data lvm2

3. Set docker warehouse address

[root@10 ~]# sudo yum-config-manager  --add-repo   https://download.docker.com/linux/centos/docker-ce.repo

4. Installation docker

[root@10 ~]# sudo yum install -y docker-ce docker-ce-cli containerd.io

由于虚拟机下载速度慢,导致docker安装不成功,设置成阿里的镜像仓库地址

sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

再次尝试

5.设置阿里云镜像加速器

url:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors

[root@10 ~]# sudo mkdir -p /etc/docker
[root@10 ~]# sudo tee /etc/docker/daemon.json <<-'EOF'
{ 
   "registry-mirrors": ["https://2a3ats4n.mirror.aliyuncs.com"]
}
EOF
[root@10 ~]# sudo systemctl daemon-reload

6.启动docker

[root@10 ~]# sudo systemctl start docker

7.安装tomcat

[root@10 ~]# docker pull tomcat
##将tomcat端口映射成centos宿主机端口 9090
[root@10 ~]# docker run -d --name my-tomcat -p 9090:8080 tomcat

成功通过宿主机ip端口访问tomcat

 

docker常用命令

image相关命令

(1) 查看本地image列表  
     docker images    
     docker image ls
(2) 获取远端镜像    
     docker pull    
(3) 删除镜像[注意此镜像如果正在使用,或者有关联的镜像,则需要先处理完]    
     docker image rm imageid    
     docker rmi -f imageid    
     docker rmi -f $(docker image ls)     删除所有镜像
(4)运行镜像    
     docker run image  
(5)发布镜像    
     docker push 

container相关命令

(1)根据镜像创建容器   
    docker run -d --name -p 9090:8080 my-tomcat tomcat  
(2)查看运行中的container    
    docker ps
(3)查看所有的container[包含退出的]    
    docker ps -a    
(4)删除container    
    docker rm containerid  
    docker rm -f $(docker ps -a)    删除所有container
(5)进入到一个container中    
    docker exec -it container bash  
(6)停止/启动容器    
    docker stop/start container
 

发布了47 篇原创文章 · 获赞 12 · 访问量 5100

Guess you like

Origin blog.csdn.net/qq_35448165/article/details/103128032