In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "case Analysis of getting started with Container Docker". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "case Analysis of getting started with Container Docker".
I. Overview
1.1 basic concepts:
Docker is an open source application container engine based on the go language and open source according to the apache2.0 protocol. Docker allows developers to package their applications and dependencies into a lightweight, portable container and publish them to any popular linux machine. Containers are completely sandboxed and do not have any interfaces to each other (similar to iphone's app). More importantly, the container performance overhead is extremely low.
1.2 advantages:
Simplify the procedure:
Docker allows developers to package their applications and dependency packages into a portable container and publish them to any popular linux machine for virtualization. Docker has changed the way it is virtualized, allowing developers to manage their work directly in docker. Convenience and rapidity is already the biggest advantage of docker. In the past, tasks that took days or even weeks could be completed in seconds under the docker container.
Savings:
On the one hand, with the advent of the era of cloud computing, developers do not have to configure high hardware in order to pursue results, and docker has changed the mindset of high performance and high price. The combination of docker and cloud makes the cloud space more fully utilized. It not only solves the problem of hardware management, but also changes the way of virtualization.
1.3 compared with traditional vm features:
As a lightweight virtualization method, docker has a significant advantage over traditional virtual machines in running applications:
The docker container is fast, and startup and stop can be achieved in seconds, which is much faster than the traditional virtual machine approach.
Docker containers require few system resources, and thousands of docker containers can be run on one host at the same time.
Docker makes it easy for users to obtain, distribute and update application images through operations similar to git. The instructions are concise and the learning cost is low.
Docker improves productivity by supporting flexible automated creation and deployment mechanisms through dockerfile configuration files.
In addition to running the applications, the docker container basically does not consume additional system resources, which ensures the application performance while minimizing the system overhead.
Docker uses a variety of protection mechanisms on the linux system to achieve strict and reliable isolation. Since version 1.3, docker has introduced security options and a mirror signature mechanism, which greatly improves the security of using docker.
Characteristic container virtual machine startup speed seconds minute hard disk generally mb generally gb performance close to native weaker than native system support thousands of containers generally dozens of isolation security isolation completely isolated
1.4 Infrastructure
Docker uses the client-server architecture mode and uses remote api to manage and create docker containers.
The docker container is created through a docker image.
The relationship between containers and mirrors is similar to objects and classes in object-oriented programming.
Docker object-oriented container object mirror class
1.5 the basis of docker technology:
Namespace, the basis of container isolation, ensures that a container cannot see b container. 6 namespaces: user,mnt,network,uts,ipc,pid
Cgroups, container resource statistics and isolation. The cgroups subsystem mainly used: cpu,blkio,device,freezer,memory
Unionfs, typical: aufs/overlayfs, the basis of hierarchical mirror implementation
1.6 docker components:
Docker client client-> initiates a request to the docker server process, such as create, stop, destroy container, etc.
Docker server server process-- > processes all docker requests and manages all containers
Docker registry image repository-- > the central repository for image storage, which can be regarded as a binary scm.
II. Installation and deployment
2.1 preparation conditions
Currently, only kernels in centos distributions support docker.
Docker runs on centos 7 and requires a 64-bit system with a kernel version of 3.10 or above.
Docker runs on centos-6.5 or later centos and requires the system to be 64-bit with kernel version 2.6.32-431 or later.
2.2 install docker
Yum install docker-y # install systemctl start docker # Startup systemctl enable docker # set Boot self-start
2.3 basic commands
Docker search centos # search for images
It is pulled from abroad by default, and the speed is very slow. You can use daocloud to configure acceleration.
Curl-ssl https://get.daocloud.io/daotools/set_mirror.sh | sh-s http://d6f11267.m.daocloud.io script is written to echo "{\" registry-mirrors\ ": [\" http://d6f11267.m.daocloud.io\"]}"> / etc/docker/daemon.jsonsystemctl restart docker # restart failed
Pull the image according to the demand:
Docker pull docker.io/ansible/centos7-ansible
Pull all the images from search:
For i in `docker search centos | awk'! / name/ {print $2}'`; do docker pull $iten done
View the local image:
Docker images
2.4 Command collation:
Container operation:
Docker create # create a container but not start it docker run # create and start a container docker stop # stop the container running, send a signal sigtermdocker start # start a stopped container docker restart # restart a container docker rm # delete a container docker kill # send a signal to the container, by default sigkilldocker attach # connect (enter) to a running container docker wait # block a container until the container stops running
Get container information:
Docker ps # displays containers with up status docker ps-a # shows all containers Including up and exited docker inspect # get all the information inside the container docker logs # View the container's stdout/stderr docker events # get the real-time events of the docker server docker port # display the container's port mapping docker top # display the container's process information docker diff # show the changes of the container's file system before and after
Export the container:
Docker cp # copy files or directories out of the container docker export # export the entire file system of the container as a tar package without layers, tag, etc.
Execute:
Docker exec # executes a command in the container and executes bash to enter the interaction
Mirror operation:
Docker images # displays a list of all local images docker import # creates an image from a tar package, often in conjunction with export using docker build # to create an image using dockerfile (recommended) docker commit # to create an image from the container docker load # to create an image from a tar package, and to use docker save # with save to save an image as a tar package Docker history # display the history command to generate a mirror with layers and tag information docker tag # give the mirror an alias
Image Repository (registry) operation:
Docker login # Log in to a registrydocker search # search for images from the registry repository docker pull # download images from the repository to the local docker push # put an image push into the registry repository
2.5 simple practical operation
Run and enter the container operation:
Docker run-I-t docker.io/1832990/centos6.5 / bin/bash
-t means to specify a pseudo terminal or terminal in the new container
-I means to allow us to interact with (stdin) in the container.
-d means that the container will be run in the background
/ bin/bash . This will start bash shell in the container
So when the container (container) starts, we get a command prompt:
In the container, we install mysql, set boot self-startup, and submit the modified image:
Docker ps-l query container iddocker commit-m "function"-a "user information" id tag submitted modified image
Docker inspect id View details docker push id upload docker Image
Using dockerfile to create Mirror
Using the command docker build, you need to create a dockerfile file that contains a set of instructions to tell docker how to build the image.
Mkdir dockerfilecd dockerfilecat > dockerfile
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.