Install docker in CentOS6

Source: Internet
Author: User
Tags docker ps

Install docker in CentOS6

Docker is an open-source application container engine that allows you to easily create a lightweight, portable, and self-sufficient container for any application. The Linux LXC, AUFS, Go language, and cgroup are used to implement resource independence and easily isolate files, resources, and networks, its ultimate goal is to achieve Application Isolation similar to the PaaS platform.

Features worth noting about Docker:

  • File System isolation: each process container runs in a completely independent root file system.

  • Resource isolation: system resources such as CPU and memory can be allocated to different containers and cgroup is used.

  • Network isolation: each process container runs in its own network space, Virtual Interface and IP address.

  • Logging: Docker collects and records the standard streams (stdout/stderr/stdin) of each process container for real-time retrieval or batch retrieval.

  • Change management: Changes to the container file system can be submitted to a new image and reused to create more containers. No template or manual configuration is required.

  • Interactive shell: Docker can allocate a virtual terminal and associate it with the standard input of any container. For example, run a *** mutual shell once.

Docker is usually used in the following scenarios:

  • Automated packaging and publishing of web applications;

  • Automated Testing and continuous integration and release;

  • Deploy and adjust databases or other background applications in a service-type environment;

  • Compile or expand the existing OpenShift or Cloud Foundry platform from scratch to build your own PaaS environment.

This article describes how to install Docker in the RedHat/CentOS environment. The official documentation requires Linux kernel to be at least 3.8, and docker can only run in 64-bit systems. Because the kernel versions of RHEL6 and CentOS6 are 2.6, you must upgrade the kernel first.

The following uses CentOS6.5 (64-bit) as an example to describe how to install and use docker:

I. Upgrade the kernel (with the aufs module)

1. Install the 3.10 kernel with the aufs module in yum (or download the kernel manual installation: http://down.51cto.com/data/1903250 here)

cd/etc/yum.repos.dwgethttp://www.hop5.in/yum/el6/hop5.repoyuminstallkernel-ml-aufskernel-ml-aufs-devel

2. Modify the main configuration file/etc/grub of grub. conf, set default = 0, which indicates that the content in the first title is the default start kernel (generally, the newly installed kernel is in the first position ).

3. restart the system. At this time, your kernel is successfully upgraded.

[root@localhost~]#uname-r3.10.5-3.el6.x86_64

Check whether the kernel supports aufs:

[root@localhost~]#grepaufs/proc/filesystemsnodevaufs

Ii. Install docker

1. First disable selinux:setenforce0sed-i'/^SELINUX=/c\SELINUX=disabled'/etc/selinux/config

2. The docker-io package has been provided in the FedoraEPEL source. Download and install epel:

rpm-ivhhttp://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpmsed-i's/^mirrorlist=https/mirrorlist=http/'/etc/yum.repos.d/epel.repo

3. Install docker-io in yum:

yum-yinstalldocker-io

4. Start docker:

servicedockerstart

5. view the docker version:

View docker logs:

cat/var/log/docker

Iii. Use of docker commands

1. directly enter the docker command to view all Options and Commands.

View the detailed usage of a command: docker COMMAND -- help

2. search for available docker images: docker search NAME

3. Download the image: docker pull NAME [: TAG]

For example, get the latest centos image: docker pull centos: latest

Note: Enter the complete image name searched using docker search.
4. view the installed image: docker images [NAME]

5. run the COMMAND in the docker container: docker run IMAGE [COMMAND] [ARG...]

The docker run Command has two parameters: one is the image name and the other is the command to be run in the image.

Note: IMAGE = REPOSITORY [: TAG]. If the IMAGE parameter does not specify the image tag, the default TAG is latest.

Output "hello word": docker run centos echo 'Hello world! '

6. List containers: docker ps-

View the recently generated container: docker ps-l

View the running container: docker ps

7. display the container's standard output: docker logs CONTAINERID

You do not need to copy the complete id. Generally, the first three to four characters are required.

8. install a new program in the container, such as the ifconfig command (ifconfig is not installed in centos7 by default): docker run centos yum install net-tools-y

If the-y parameter is not specified for yum, the yum command enters the interaction mode. You need to enter a command to confirm that the interaction cannot be responded to in the docker environment. However, the-I-t parameter of docker run will respond to this interaction. You can enter the command, for example, docker run-I-t centos yum install net-tools.

9. Save the changes to the container and generate a new image: docker commit CONTAINERID [REPOSITORY [: TAG]

The REPOSITORY parameter can be a new image name or an old image name. If the old image name and TAG are the same, the old image will be overwritten.

10. stop a running container: docker stop CONTAINERID

By default, the specified container is killed after 10 seconds. You can use the-t parameter to set the wait time.

11. view the container or IMAGE details: docker inspect CONTAINERID | IMAGE

The parameter can be the container ID or image NAME (NAME: TAG ).

12. delete a container: docker rm CONTAINERID

View All container IDs: docker ps-a-q

Delete all containers: docker rm $ (docker ps-a-q)

13. delete an IMAGE: docker rmi IMAGE

14. View docker information, including the number of Containers, Images, and kernel versions.

4. Create a container and log on to the container

1. Create a new container and log on to: docker run-I-t IMAGE/bin/bash

Use the image to create a iner and enter the interactive mode. The login shell is/bin/bash. Now you can operate the container freely. Use exit to exit the container.

NOTE: If no TAG is specified for the IMAGE parameter, the default TAG is latest.

2. start an exited container: docker start CONTAINERID

3. attach to the running container: docker attach CONTAINERID

This article is from the "Departure Linux blog" blog, please be sure to keep this source http://qicheng0211.blog.51cto.com/3958621/1582909

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.