Docker学习

官方文档:Install Docker Engine on CentOS | Docker Documentation

安装

  1. #1、卸载旧版本
  2. yum remove docker \
  3. docker-client \
  4. docker-client-latest \
  5. docker-common \
  6. docker-latest \
  7. docker-latest-logrotate \
  8. docker-logrotate \
  9. docker-engine
  10. #2、需要的安装包
  11. yum install -y yum-utils
  12. #3、设置镜像的仓库,镜像源建议替换为阿里云的
  13. yum-config-manager \
  14. --add-repo \
  15. https://download.docker.com/linux/centos/docker-ce.repo#默认是国外的
  16. yum-config-manager \
  17. --add-repo \
  18. http:mirrors.aliyum.com/docker-ce/linux/contos/docker-re.repo
  19. #更新yum软件包索引
  20. yum makecache fast
  21. #4、安装docker的相关版本,docker-ce社区版 ee企业版
  22. yum install docker-ce docker-ce-cli containerd.io
  23. #5、启动docker
  24. systemctl start docker
  25. #6、使用docker version 检查是否启动成功
  26. [root@docker-study ~]# docker version
  27. Client: Docker Engine - Community
  28. Version: 20.10.12
  29. API version: 1.41
  30. Go version: go1.16.12
  31. Git commit: e91ed57
  32. Built: Mon Dec 13 11:45:41 2021
  33. OS/Arch: linux/amd64
  34. Context: default
  35. Experimental: true
  36. Server: Docker Engine - Community
  37. Engine:
  38. Version: 20.10.12
  39. API version: 1.41 (minimum version 1.12)
  40. Go version: go1.16.12
  41. Git commit: 459d0df
  42. Built: Mon Dec 13 11:44:05 2021
  43. OS/Arch: linux/amd64
  44. Experimental: false
  45. containerd:
  46. Version: 1.4.12
  47. GitCommit: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
  48. runc:
  49. Version: 1.0.2
  50. GitCommit: v1.0.2-0-g52b36a2
  51. docker-init:
  52. Version: 0.19.0
  53. GitCommit: de40ad0
  54. #运行镜像测试
  55. [root@docker-study ~]# docker run hello-world
  56. Hello from Docker!
  57. This message shows that your installation appears to be working correctly.
  58. To generate this message, Docker took the following steps:
  59. 1. The Docker client contacted the Docker daemon.
  60. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
  61. (amd64)
  62. 3. The Docker daemon created a new container from that image which runs the
  63. executable that produces the output you are currently reading.
  64. 4. The Docker daemon streamed that output to the Docker client, which sent it
  65. to your terminal.
  66. To try something more ambitious, you can run an Ubuntu container with:
  67. $ docker run -it ubuntu bash
  68. Share images, automate workflows, and more with a free Docker ID:
  69. https://hub.docker.com/
  70. For more examples and ideas, visit:
  71. https://docs.docker.com/get-started/
  72. #查看镜像
  73. [root@docker-study ~]# docker images
  74. REPOSITORY TAG IMAGE ID CREATED SIZE
  75. hello-world latest feb5d9fea6a5 4 months ago 13.3kB