Share basic concepts about Docker

  • 2020-06-01 11:22:36
  • OfStack

Introduction to the

As stated in the official documentation, docker is an engine that automatically packages applications into lightweight, portable, self-contained containers. Applications built by developers can run on the full platform at once, including local development machines, production environments, virtual machines, and the cloud. It is currently in development and is not available for production. When you start a command, docker will call lcx and other components to build an container for this command, which contains all the resources that the process is running on. However, official documentation indicates that docker is in development and is not currently available for production.

features

Go language writing
Process-level isolation based on lxc, and lxc based on cgroup, lightweight
File system, network and resource isolation via cgroup
Use aufs file system for storage, copy when writing, save only one copy of the same data, save space
Source mechanism, can share with each other, search and so on

concept

cgroups

cgroups, control groups in full, is a mechanism provided by the linux kernel to restrict, record, and isolate the physical resources used by process groups. cgroups has been supported in kernels since 2.6.24. Please refer to cgroups for details.

lxc

lxc, linux container in full, is a set of tools for building virtual environments based on kernel features such as cgroups and chroot. You can create, modify, and delete virtual environments using the series 1 command line tools. Specific usage can be referred to the ubuntu official documentation.

aufs

aufs, advance(another) union file system, is a federated file system. One of the most important features of this file system is the concept of having one layer and copying when copying, so that when the file system changes, only one layer is affected and the other layer remains the same. For example, the entire file system is made up of layer after layer of glass. You can see all the patterns from the top down (if the upper and lower layers of glass overlap, you can only see the upper layer of glass), and you can only operate on the upper layer of glass when you need to add or modify a pattern. For specific examples, please refer to the aufs demonstration of geekstuff

The installation

Note: docker requires a kernel of 3.8 or above, so the recommended installation system is ubuntu.

ubuntu

curl -s https://get.docker.io/ubuntu/ | sudo sh

centos

Install epel rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

Install docker yum install -y docker-io

Start the service docker start chkconfig docker on

use

The command line

Get base image

docker pull ubuntu

This command will fetch the ubuntu image from docker index, which is the basis for running other processes.

Run the command

docker run -i -t ubuntu yum install -y vim

Submit the change


docker images
docker commit id user/name
docker push user/name

Run again


docker pull user/name
docker run -i -t image vim


Note: rerun here means that the environment you are building can run on any other platform, with no additional configuration and no dependencies.

Dockerfile

dockerfile describes all aspects of an image by means of some instructions.


# Memcached
#
# VERSION    2.2
# use the ubuntu base image provided by dotCloud
FROM ubuntu
MAINTAINER Victor Coisne victor.coisne@dotcloud.com
# make sure the package repository is up to date
RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
RUN apt-get update
# install memcached
RUN apt-get install -y memcached
# Launch memcached when launching the container
ENTRYPOINT ["memcached"]
# run memcached as the daemon user
USER daemon
# expose memcached port
EXPOSE 11211

Some of these instructions explain:

FROM specifies base image for this image
MAINTAINER specifies the maintainer of image
RUN specifies the command to run under the current image, equivalent to docker run image command
ENTRYPOINT specifies the command to be fired when image is run
USER specifies the user name to run the start command
EXPOSE specifies the port number to be supplied

That's all for this article, and I hope it will help you understand docker


Related articles: