Ubuntu Docker Introduction and installation use

Source: Internet
Author: User
Tags format message docker ps docker run

What is Docker?

Docker is an open-source application container engine, system-level lightweight virtualization technology.

An automated deployment solution for applications that can quickly create a container, deploy and run applications on containers, and easily automate the installation, deployment, and upgrade of applications with configuration files.

Using the Go language, Docker uses Cgroup for resource isolation, and container technology with LXC,LXC is a kernel virtualization technology that provides lightweight virtualization. LXC is a feature of the Linux kernel that allows a process or group of processes to run in a separate space and be able to control it. and implement the container and host resource sharing.

Advantages?

1. Lightweight resources, containers are isolated at the process level and use the host's kernel without the need to virtualize the entire operating system. Complex operations are not required for virtualization and system calls. So it saves a lot of extra overhead. No additional hypervisor (virtualization Technology) support is required, no virtual hardware required, no additional complete system required.

2. Portability, required applications are in the container, can be run on any one Docker host

3. Predictability, the host and the container do not care about each other's running what. Only consider the required interface normalization.

Related components and functions?

1.lxc,docker is the manager of LXC. Provides a range of more powerful features, such as portability (defined standards, can be run on any host), automated Build (Dockerfile), versioning, image sharing, and more.

2.CGROUP,LXC is a management tool for Cgroup. Restricts the management of system resources used by processes or process groups. Provides a file-like interface that is very easy to configure.

3.namespace,cgroup is the management interface for namespace user space. and isolate the process or process group, if net, MNT, PID, user, and so on.

4.aufs (ANOTHERUNIONFS), supports mounting different directories to the same virtual file system. The Docker container is divided into a read-only mirror layer and a writable layer above, and the AUFS implements incremental modifications on the writable layer (incremental file system).

The types of federated file systems currently supported by Docker include AUFS, Btrfs, VFS, and Devicemapper

5.chroot to enable the container to run within the specified directory.

Relationships between components?

Cgroup is the bottom-level implementation of resource management, LXC on the Cgroup package a layer, Docker and LXC encapsulated a layer.

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/78/9E/wKioL1Z_-iXjQvrfAAD8YQ9PScM534.png "title=" Clipboard.png "alt=" Wkiol1z_-ixjqvrfaad8yq9pscm534.png "/>

How does it work?

When we launch a Docker container, Docker loads the read-only image and adds a read-write layer on it (copy the Mirror directory to/var/lib/docker/aufs/mnt in the ID directory, we can use Chroot to enter this directory, Same as the directory inside the container). If a running container modifies an existing file that already exists, the file will be copied from the read-only layer below it to the read-write layer, the read-only version of the file still exists, but it is hidden by a copy of the file in the read-write layer, and when the Docker container is deleted and restarted through the mirror, The previous changes will be lost.

In Docker, the combination of the read-only layer and the read-write layer at the top is called the Union file System,ufs (Federated filesystem)


Blog Address: http://lizhenliang.blog.51cto.com


Docker Installation and use:

1. Add secret Key

$ sudo apt-key adv--keyserver hkp://pgp.mit.edu:80--recv-keys 58118e89f3a912897c070adbf76221572c52609d

2. Add a Docker source

$ sudo vi/etc/apt/sources.list.d/docker.list

# Ubuntu Precise

Deb Https://apt.dockerproject.org/repo ubuntu-precise Main

# Ubuntu Trusty

Deb Https://apt.dockerproject.org/repo ubuntu-trusty Main

# Ubuntu Vivid

Deb Https://apt.dockerproject.org/repo Ubuntu-vivid Main

# Ubuntu Wily

Deb Https://apt.dockerproject.org/repo ubuntu-wily Main

Note: Use the command Lsb_release-cs to view the corresponding version above, do not add

3. Update Index

$ sudo apt-get update

4. Installing Docker

$ sudo apt-get install Docker-engine

5. Download Ubuntu image

#默认下载最新版

$ sudo docker pull Ubuntu

#如果想下载14.04 version, can be specified in this way

$ sudo docker pull ubuntu:14.04

6. Print Hello in the mirror

$ sudo docker run Ubuntu/bin/echo hello

Print out Hello instructions you have successfully installed Docker and started a container!

7, familiar with the common command

#查看docker环境信息

$ sudo docker version

# sudo docker-d info

#在仓库中搜索相关的镜像

$ sudo docker search CentOS

#查看已下载的镜像

$ sudo docker images

#启动镜像并进入容器

$ sudo docker run-itd--name=ubuntu ubuntu

Run command options:

-T simulates a terminal,-I enters this container, which is typically used in conjunction with creating an interactive container.

-D background runs the container and prints the ID and cannot be appended to the container if you do not add-I

--name specifying a name for a container

There are many options for the Run command, but you will learn more about it in use!

Now that you have created and entered the container, how can you quit?

# Press Ctrl+d to exit the container, the container will be paused, can be restarted (sudo docker start id/name), the data will not be lost.

# Quit suspending containers It's not common sense! Then press Ctrl+p+q to exit Docker and will not pause

#紧接查看运行的容器

$ sudo docker PS

#这时想进入某个容器可通过ps查看的ID进入运行的容器

$ sudo docker attach Id/name

#关闭运行的容器 (Start/restart)

$ sudo docker stop ID

#关闭所有运行的容器

$ sudo docker kill $ (sudo docker ps-q) #-q only display ID

#删除一个容器

$ sudo docker rm id/name

#删除所有容器

$ sudo docker rm $ (sudo docker ps-q)

#删除一个镜像

$ sudo docker rmi ID

#查看Docker操作日志

$ sudo docker ps-a

#查看容器日志

$ sudo docker logs Id/name

#查看容器配置详细信息

$ sudo docker inspect ID

At this point, a JSON format message is returned and we can get the specified information, such as obtaining an IP address:

$ sudo docker inspect-f ' {{. Networksettings.ipaddress}} ' ID

#列出容器内容文件状态变化情况

$ sudo docker diff ID

Note: A-add,d-delet, C-change

#查看容器资源使用情况

$ sudo docker stats

#免交互执行命令

$ sudo docker exec id/name command


With this blog post, you already have a preliminary understanding of Docker and can easily manage the container!

The next step is to update the contents of the Docker, welcome attention, Thank you for your support!

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/78/9F/wKioL1Z__S3R2uT7AADwM4Z-rk4073.png "title=" QQ picture 20151227230020.png "alt=" Wkiol1z__s3r2ut7aadwm4z-rk4073.png "width=" "height=" "0" border= "0" Vspace= "0" style= "width:100px;height:82px;"/>


Reference Document: Https://docs.docker.com/engine/installation/ubuntulinux


This article is from the "Li Zhenliang Technology Blog" blog, make sure to keep this source http://lizhenliang.blog.51cto.com/7876557/1728931

Ubuntu Docker Introduction and installation use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.