Docker installation (centos6.x system)

Docker.io is a lightweight "container engine + image repository" built on the basis of LXC (Linux Lightweight Containers), which can run any application.


installation steps:

  • This installation tutorial is based on centos6.8 and is suitable for all versions above centos6.5

1. Disable selinux

  • Because selinux and LXC conflict, it needs to be disabled
vim /etc/selinux/config
设置SELINUX=disabled

2. Install Fedora EPEL

yum -y install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

3. Check the kernel version

  • Kernel version >= 2.6.32-431 is required when running CentOS 6.5 and later, as these kernels contain some modifications specific to running Docker
[root@localhost phq]# uname -r
2.6.32-642.1.1.el6.x86_64
[root@localhost phq]# cat /etc/redhat-release
CentOS release 6.8 (Final)

4. Remove Docker (optional)

  • In CentOS 6.5, there is already an executable system package with the same name as docker. So the DockerRPM package is named docker-io, and we first uninstall docker.
yum -y remove docker

5. Install docker-io

yum install docker-io

6. Start

service docker start

7. Set startup (optional)

chkconfig docker on

8. Verify docker installation

  • After starting the service, directly use the docker info command to confirm whether docker is installed and running correctly
docker info

9. Get the centos image

  • Docker official source is used by default
docker pull centos
  • Due to the special domestic network environment, using the default official repository (Docker Hub) to obtain images is relatively slow.

10. View images

[root@localhost phq]# docker images centos
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              latest              3aa28fd030d9        12 days ago         196.8 MB

11. Start the container

  • The container runs on the basis of the image. Once the container is started, we can log in to the container and install the software or applications we need.
[root@localhost phq]# docker run -i -t 3aa28fd030d9 /bin/bash
  • The startup command consists of the following three parts:
docker run <相关参数> <镜像 ID> <初始命令>
  • Related parameters:
-i:表示以“交互模式”运行容器
-t:表示容器启动后会进入其命令行
-v:表示需要将本地哪个目录挂载到容器中,格式:-v <宿主机目录>:<容器目录>
  • Assuming that all our installers are placed in the host's /root/software/ directory, we now need to mount them in the container's /mnt/software/ directory
[root@localhost phq]# docker run -i -t -v /root/software/:/mnt/software/ 3aa28fd030d9 /bin/bash
  • It should be noted that it is not necessary to use "mirror ID", you can also use "repository name: tag name", for example:
centos:latest
  • [x] The initial command indicates the command that needs to be run once the container is started. In this case, "/bin/bash" is used, which means to do nothing, just enter the command line.

12. Exit the container

  • You can use the exit command to exit the container. Then, you can view the running container with the following command:
[root@localhost phq]# docker ps
  • At this point, you should not see any running programs, because the container you just exited with the exit command is in a stopped state

13. View all containers

[root@localhost software]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
ada0dda40fb1        3aa28fd030d9        "/bin/bash"         About an hour ago   Exited (0) 54 minutes ago                       thirsty_blackwell  

14. Delete the container

[root@localhost software]# docker rm ada0dda40fb1

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325495956&siteId=291194637