centOs7 安装 docker

矫情吗;* 2022-04-23 03:32 186阅读 0赞

1.查看你的centos内核版本

Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的CentOS 版本是否支持 Docker 。

通过 uname -r 命令查看你当前的内核版本

  1. [root@default docker]# uname -r
  2. 3.10.0-957.1.3.el7.x86_64

2.安装Docker

  1. [root@localhost ~]# yum remove docker \
  2. docker-client \
  3. docker-client-latest \
  4. docker-common \
  5. docker-latest \
  6. docker-latest-logrotate \
  7. docker-logrotate \
  8. docker-selinux \
  9. docker-engine-selinux \
  10. docker-engine

首先移除你的centOs上的老版本Docker,没安装过的话可以不进行这步操作。

安装docker需要的系统工具

  1. [root@localhost ~]# sudo yum install -y yum-utils device-mapper-persistent-data lvm2

添加软件源信息(未添加用aliyun centos linux自带了):

  1. [root@localhost ~]# sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

更新 yum 缓存 :

  1. [root@localhost ~]# sudo yum makecache fast

配置官方yum源,启用稳定版源配置:

  1. echo '[docker-ce-stable]
  2. name=Docker CE Stable - $basearch
  3. baseurl=https://download.docker.com/linux/centos/7/$basearch/stable
  4. enabled=1
  5. gpgcheck=1
  6. gpgkey=https://download.docker.com/linux/centos/gpg
  7. [docker-ce-stable-debuginfo]
  8. name=Docker CE Stable - Debuginfo $basearch
  9. baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/stable
  10. enabled=0
  11. gpgcheck=1
  12. gpgkey=https://download.docker.com/linux/centos/gpg
  13. [docker-ce-stable-source]
  14. name=Docker CE Stable - Sources
  15. baseurl=https://download.docker.com/linux/centos/7/source/stable
  16. enabled=0
  17. gpgcheck=1
  18. gpgkey=https://download.docker.com/linux/centos/gpg
  19. [docker-ce-edge]
  20. name=Docker CE Edge - $basearch
  21. baseurl=https://download.docker.com/linux/centos/7/$basearch/edge
  22. enabled=0
  23. gpgcheck=1
  24. gpgkey=https://download.docker.com/linux/centos/gpg
  25. [docker-ce-edge-debuginfo]
  26. name=Docker CE Edge - Debuginfo $basearch
  27. baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/edge
  28. enabled=0
  29. gpgcheck=1
  30. gpgkey=https://download.docker.com/linux/centos/gpg
  31. [docker-ce-edge-source]
  32. name=Docker CE Edge - Sources
  33. baseurl=https://download.docker.com/linux/centos/7/source/edge
  34. enabled=0
  35. gpgcheck=1
  36. gpgkey=https://download.docker.com/linux/centos/gpg
  37. [docker-ce-test]
  38. name=Docker CE Test - $basearch
  39. baseurl=https://download.docker.com/linux/centos/7/$basearch/test
  40. enabled=0
  41. gpgcheck=1
  42. gpgkey=https://download.docker.com/linux/centos/gpg
  43. [docker-ce-test-debuginfo]
  44. name=Docker CE Test - Debuginfo $basearch
  45. baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/test
  46. enabled=0
  47. gpgcheck=1
  48. gpgkey=https://download.docker.com/linux/centos/gpg
  49. [docker-ce-test-source]
  50. name=Docker CE Test - Sources
  51. baseurl=https://download.docker.com/linux/centos/7/source/test
  52. enabled=0
  53. gpgcheck=1
  54. gpgkey=https://download.docker.com/linux/centos/gpg
  55. [docker-ce-nightly]
  56. name=Docker CE Nightly - $basearch
  57. baseurl=https://download.docker.com/linux/centos/7/$basearch/nightly
  58. enabled=0
  59. gpgcheck=1
  60. gpgkey=https://download.docker.com/linux/centos/gpg
  61. [docker-ce-nightly-debuginfo]
  62. name=Docker CE Nightly - Debuginfo $basearch
  63. baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/nightly
  64. enabled=0
  65. gpgcheck=1
  66. gpgkey=https://download.docker.com/linux/centos/gpg
  67. [docker-ce-nightly-source]
  68. name=Docker CE Nightly - Sources
  69. baseurl=https://download.docker.com/linux/centos/7/source/nightly
  70. enabled=0
  71. gpgcheck=1
  72. gpgkey=https://download.docker.com/linux/centos/gpg'>/etc/yum.repos.d/docker-ce.repo

查看可用的docker-ce版本:

  1. [root@localhost ~]# yum list docker-ce --showduplicates|grep "^doc"|sort -r
  2. docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable
  3. docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
  4. docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
  5. docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable
  6. docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable
  7. docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable
  8. docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable
  9. docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stable
  10. docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stable
  11. docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stable
  12. docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stable
  13. docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable
  14. docker-ce.x86_64 17.03.3.ce-1.el7 docker-ce-stable
  15. docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable
  16. docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
  17. docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable

安装 Docker-ce:

  1. [root@localhost ~]# sudo yum -y install docker-ce-18.06.1.ce-3.el7
  2. [root@localhost ~]# docker version
  3. Client:
  4. Version: 18.06.1-ce
  5. API version: 1.38
  6. Go version: go1.10.3
  7. Git commit: e68fc7a
  8. Built: Tue Aug 21 17:23:03 2018
  9. OS/Arch: linux/amd64
  10. Experimental: false
  11. Server:
  12. Engine:
  13. Version: 18.06.1-ce
  14. API version: 1.38 (minimum version 1.12)
  15. Go version: go1.10.3
  16. Git commit: e68fc7a
  17. Built: Tue Aug 21 17:25:29 2018
  18. OS/Arch: linux/amd64
  19. Experimental: false

docker 常用的几个命令:

查看docker服务状态、启动docker服务、停止docker服务、重启docker服务

  1. systemctl status docker
  2. systemctl start docker
  3. systemctl stop docker
  4. systemctl restart docker

设置为linux开机启动

  1. [root@localhost ~]# systemctl enable docker
  2. Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

hello-world测试一下docker

  1. [root@default docker]# docker run hello-world
  2. Hello from Docker!
  3. This message shows that your installation appears to be working correctly.
  4. To generate this message, Docker took the following steps:
  5. 1. The Docker client contacted the Docker daemon.
  6. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
  7. (amd64)
  8. 3. The Docker daemon created a new container from that image which runs the
  9. executable that produces the output you are currently reading.
  10. 4. The Docker daemon streamed that output to the Docker client, which sent it
  11. to your terminal.
  12. To try something more ambitious, you can run an Ubuntu container with:
  13. $ docker run -it ubuntu bash
  14. Share images, automate workflows, and more with a free Docker ID:
  15. https://hub.docker.com/
  16. For more examples and ideas, visit:
  17. https://docs.docker.com/get-started/

第一次run hello-world的时候,因为本地没有hello-world镜像,docker引擎会自己去docker hub搜索hello-world,拉取,并运行

用docker search hello-world查看一下远端镜像库中的hello-world镜像,结果如下:

  1. [root@default docker]# docker search hello-world
  2. NAME DESCRIPTION STARS OFFICIAL AUTOMATED
  3. hello-world Hello World! (an example of minimal Dockeriz 804 [OK]
  4. kitematic/hello-world-nginx A light-weight nginx container that demonstr 119
  5. tutum/hello-world Image to test docker deployments. Has Apache 59 [OK]
  6. dockercloud/hello-world Hello World! 14 [OK]
  7. hypriot/armhf-hello-world Hello World! (an example of minimal Dockeriz 6
  8. crccheck/hello-world Hello World web server in under 2.5 MB 6 [OK]
  9. armhf/hello-world Hello World! (an example of minimal Dockeriz 5
  10. marcells/aspnet-hello-world ASP.NET vNext - Hello World 5 [OK]
  11. kornkitti/express-hello-world Node.js Express Hello World : https://github… 3
  12. bonomat/nodejs-hello-world a simple nodejs hello world container 3 [OK]
  13. ppc64le/hello-world Hello World! (an example of minimal Dockeriz 2
  14. hello-seattle Hello from DockerCon 2016 (Seattle)! 2 [OK]
  15. arm32v7/hello-world Hello World! (an example of minimal Dockeriz 1
  16. microsoft/mcr-hello-world Hello World! (an example of minimal Dockeriz 1
  17. carinamarina/hello-world-app This is a sample Python web application, run 1 [OK]
  18. ansibleplaybookbundle/hello-world-apb An APB which deploys a sample Hello World! a 0 [OK]
  19. ansibleplaybookbundle/hello-world-db-apb An APB which deploys a sample Hello World! a 0 [OK]
  20. mcrflowtest/mcr-hello-world Hello World! (an example of minimal Dockeriz 0
  21. gscrivano/hello-world hello world example system container 0 [OK]
  22. s390x/hello-world Hello World! (an example of minimal Dockeriz 0
  23. markmnei/hello-world-java Automated build of Hello World Java 0 [OK]
  24. burdz/hello-world-k8s To provide a simple webserver that can have 0 [OK]
  25. kevindockercompany/hello-world 0
  26. infrastructureascode/hello-world A tiny "Hello World" web server with a healt 0 [OK]
  27. winamd64/hello-world Hello World! (an example of minimal Dockeriz 0

发表评论

表情:
评论列表 (有 0 条评论,186人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Centos 7 Docker安装

    > 如果我的博客能够帮到大家能够点个赞,关注一下,以后还会更新更过JavaWeb的高级技术,大家的支持就是我继续更新的动力。谢谢。 > Docker 是一个开源的应用容器引擎

    相关 CentOS7安装Docker

    一、Docker简介           Docker 是一个[开源][Link 1]的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到