1. Introduction:
Docker is an open source application container, based on the Go language and open source in compliance with the Apache2.0 protocol. Docker allows developers to package their applications into a lightweight, portable container, and then publish it to any popular Linux machine. Virtualization can also be achieved. Containers completely use the sandbox mechanism, and there will be no interfaces between them, and the performance overhead of the containers is extremely low.
2. Docker architecture:
Images: docker image, a template used to create Docker containers.
Container: docker container, one or a group of applications that run independently.
Client: docker client, use docker Api to communicate with the docker daemon
Host: docker host, a physical or virtual machine used to execute docker daemon and containers, such as cetnos, ubuntu, etc.
Registry: docker warehouse, used to save images.
Machine: A command line tool that simplifies docker installation, such as VirtualBox, Digital Ocean, Microsoft Azure.
Three, Docker first experience
Install docker on centos7:
yum install -y docker default installation
docker-ce installation:
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum install docker-ce
Test whether the installation is successful: service docker start—start docker, docker version view docker version
Four: Docker conventional usage:
Docker operation:
Version / information—— docker [version / info]
Container operation:
Container life cycle management: docker 【run | start | stop | restart | kill | rm | pause | unpause】
Container operation and maintenance: docker 【ps | inspect | exec | logs | export | import | port】
Container rootfs command: docker [commit | cp | diff]
Mirror operation:
Image management: docker [images | rmi | tag | build |history | save | import]
Warehouse operations:
Mirror warehouse: docker [login | pull | push | seacher]
Five: container use
docker run: create a container and run a command
docker create: Create a container, but do not start
-d: Run the container in the background
-i: Run the container in interactive mode, usually used with -t
-p: port mapping, the format is: host (host) port: container port
-t: Reallocate a pseudo terminal for the container, usually used with -i
--name="zk": Specify a name for the container
--dns 8.8.8.8: Specify the DNS server used by the container, the default is the same as the host
-m: Set the maximum memory usage of the container
--net="bridge": network connection type, support bridge/host/none/container: four types;
--link=[]: add a link to another container
--expose=[]: open a port or a group of ports
A container is an application or a group of applications that run independently, and their operating environment;
Create a container interactively and enter: docker run -it --name centos centos /bin/bash (foreground process)
exit: Exit and close the container;
Ctrl+P+Q: Exit without closing the container;
Start the container in the background: docker run -d --name nginx (container name) nginx (image name)
Enter the running container: docker exec -it nginx /bin/bash
View the metadata of the container: docker inspect nginx
Bind the container port to the host: docker run -d -p 8080:80 --name nginx nginx:latest
Mount the host file directory to the container: docker run -dit -v/root/peter_dir/;/pdir --name cent centos
Copy the host file to the container: docker run -dit -v /root/peter_dir/:/pdir --name cent centos
Copy the host file directory to the container: docker cp anaconda-ks.cfg
Copy the host file to the container: docker cp anaconda-ks.cfg cent:/var
6. Warehouse use:
Repository is a place where mirror images are stored centrally
Docker official warehouse: https://hub.docker.com, free registration, email activation
Common commands: Docker pull / search / login /push / tag
Tag: mark the local mirror and put it into a warehouse
Push: Push the image to the warehouse --- login is required
Search: Query the mirror in the warehouse --- The tag version cannot be found
Pull: Download the mirror image to the local
Login: Login to the warehouse
7. The use of private warehouse:
Use the registry image to create a private warehouse, download the registry image: docker pull registry
Configurable accelerator to accelerate download
vi /etc/docker/daemon.json
{
"bip":"127.17.5.1/24",
"registry-mirrors":["https://registry.docker-cn.com"]
}
Start: docker run -d --name reg -p 5000:5000 registry
Set http transmission: systemctl daemon-reload |systemctl restart docker
vi /etc/docker/daemon.json
{
"bip":"127.17.5.1/24",
"registry-mirrors":["https://registry.docker-cn.com"],
"insecure-registries":["192.168.244.5:5000"]
}
docker tag hello-world http://192.168.244.5:5000/hello-world
docker push 192.168.244.5:5000/hello-world
Query: curl http://192.168.244.5:5000/v2/_catalog | http://192.168.244.5:5000/v2/hello-world/tags/list