Installation of docker under CentOS6.5 and problems encountered and simple use

Docker is an open source application container engine that makes it easy to create a lightweight, portable, self-sufficient container for any application. Using Linux's LXC, AUFS, Go language, and cgroup to achieve resource independence, you can easily isolate files, resources, and networks. The ultimate goal is to achieve application isolation similar to PaaS platforms.

    Notable features of 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 using cgroups.

  • Network isolation: Each process container runs in its own network space, virtual interface and IP address.

  • Logging: Docker will collect and log standard streams (stdout/stderr/stdin) per process container for real-time retrieval or batch retrieval.

  • Change Management: Changes to a container's filesystem can be committed to a new image and reused to create more containers. No templates or manual configuration required.

  • Interactive shell: Docker can allocate a virtual terminal and attach it to the standard input of any container, for example to run a one-time interactive shell.

    Docker is usually used in the following scenarios:

  • Automated packaging and publishing of web applications;

  • Automated testing and continuous integration, release;

  • Deploy and tune databases or other background applications in a service-based environment;

  • Build your own PaaS environment by compiling or extending an existing OpenShift or Cloud Foundry platform from scratch.

    This article describes how to install Docker in a RedHat/CentOS environment. Official documents require that the Linux kernel be at least 3.8 or above, and docker can only run on 64-bit systems. Since the kernel version of RHEL6 and CentOS6 is 2.6, the kernel must be upgraded first.

    The following takes CentOS6.5 (64-bit) as an example to introduce the docker installation steps and usage:

1. Upgrade the kernel (with aufs module, remember to upgrade, otherwise there will be many inexplicable problems, it is recommended to use yum to install)

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

1
2
3
cd  /etc/yum .repos.d 
wget http: //www .hop5. in /yum/el6/hop5 .repo
yum  install  kernel-ml-aufs kernel-ml-aufs-devel

    2. Modify grub's main configuration file /etc/grub.conf and set default=0, which means that the content under the first title is the kernel that is started by default (generally the newly installed kernel is in the first position).

wKiom1R1XF_BWoKPAAPcDXlNx-A406.jpg

    3. Restart the system. At this time, your kernel has been successfully upgraded.

1
2
[root@localhost ~] # uname -r
3.10.5-3.el6.x86_64

    Check if the kernel supports aufs:

1
2
[root@localhost ~] # grep aufs /proc/filesystems
nodev    aufs

2. Install docker

    1、首先关闭selinux:
1
2
setenforce 0
sed  -i  '/^SELINUX=/c\SELINUX=disabled'  /etc/selinux/config

    2. The docker-io package has been provided in the Fedora EPEL source, download and install epel:

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

    3. yum install docker-io:

1
yum -y  install  docker-io

wKioL1R2oWOCRxohAAONGaU5ZIs803.jpg

    4. Start docker:

1
service docker start

wKioL1R1QBaDsuZ9AACThIbJ9Eo954.jpg

    5. Check the docker version:

wKioL1R1ejWCsWMqAAGVpn-s-Uk526.jpg

    View docker logs:

1
cat  /var/log/docker

Third, the use of docker commands

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

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

wKiom1R1dHbzIJLfAADQR3jiJtM669.jpg 

    2. Search for available docker images: docker search NAME

wKiom1R1Z2eDpDhPAAS6paTJagQ409.jpg 

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

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

    Note: Write the full image name searched by docker search here.
    4. View the installed image: docker images [NAME]

wKiom1R1c7LgL0uwAADPCgcMWqw663.jpg 

    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 run in the image.

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

    Output "hello word" in the image you just downloaded: docker run centos echo 'hello world!'wKiom1R1c3fj6XQFAABqRD8XV6o479.jpg 

    6. List containers: docker ps -a

    View recently generated containers: docker ps -l

    View running containers: docker ps

    7. Display the standard output of the container: docker logs CONTAINERID

    There is no need to copy the complete id, generally write the first three to four characters.

wKiom1R1m_STX0iUAAGRjbJx35o891.jpg 

    8. Install new programs in the container, such as installing the ifconfig command (centos7 does not have ifconfig by default): docker run centos yum install net-tools -y

    If yum does not specify the -y parameter, the yum command will enter the interactive mode, requiring the user to enter a command for confirmation, which cannot be responded to in the docker environment. But using the -i -t parameters of docker run will respond to this interaction, and the user can enter commands, such as: 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 the new image name or the old image name; if the name and TAG of the old image are the same, the old image will be overwritten.

wKiom1R1lhuQSjeFAAYdjYDJl7g665.jpg

    10. Stop the running container: docker stop CONTAINER ID

    By default wait 10 seconds before killing the specified container. The wait time can be set with the -t parameter.

wKioL1R1eVaAon28AAFM9IS_WPk474.jpg 

    11. View the details of the container or image: docker inspect CONTAINER ID |IMAGE

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

wKioL1R1e8uSeslZAAIcWL54yBA017.jpg 

    12. Delete the container: docker rm CONTAINERID

    View all container IDs: docker ps -a -q

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

    13. Delete the image: docker rmi IMAGE

wKioL1R1oW-gqMmrAALqpTRiwN8314.jpg

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

wKiom1R1sCDBp_afAAEBBnNOVBo956.jpg

Fourth, the operation of creating a container and logging in

    1. Create a new container and log in: docker run -i -t IMAGE /bin/bash

    Use the image to create a container and enter the interactive mode, the login shell is /bin/bash, and now you can freely operate the container. Finally use exit to exit the container.

    Note: If the IMAGE parameter does not specify TAG, the default TAG is latest.

    2. Start an exited container: docker start CONTAINERID

    3. Attach to the running container: docker attach CONTAINERID

wKiom1R1pBST_fU7AAOkWUKDLA0506.jpg

 

 

 

Reprint address: http://blog.csdn.net/wuzhilon88/article/details/41621285/

 
 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327038214&siteId=291194637