Docker 学习笔记

£可爱£侵袭症+ 提交于 2020-07-28 18:51:48

简单的记录一下Docker的学习笔记。 首先看看如何安装。

以AWS EC2 Redhat 为例,安装一个EC2 实例,然后SSH进入界面。

根据老师的建议,首先关闭firewalld的防火墙和SELinux,以避免不必要的问题,安装docker之后他会自动安装配置一个iptables的防火墙。EC2的Redhat现在是version 8 的版本,默认没有安装firewalld和 iptable,这一步可以跳过;

修改selinux配置文件,然后重启

[root@ip-172-16-2-231 /]# cat /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

接下来,访问https://docs.docker.com/ 根据他的文档,安装docker。

先安装yum-utils的工具,然后添加一个repo

yum install -y yum-utils
Last metadata expiration check: 0:41:32 ago on Wed 22 Jul 2020 05:53:29 AM UTC.
Package yum-utils-4.0.12-3.el8.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!

yum-config-manager     --add-repo     https://download.docker.com/linux/centos/docker-ce.repo
Adding repo from: https://download.docker.com/linux/centos/docker-ce.repo

接下来按照他的文档按照会报错,

yum install docker-ce docker-ce-cli containerd.io

Error:
 Problem: package docker-ce-3:19.03.8-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
  - cannot install the best candidate for the job
  - package containerd.io-1.2.10-3.2.el7.x86_64 is excluded
  - package containerd.io-1.2.13-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.2-3.3.el7.x86_64 is excluded
  - package containerd.io-1.2.2-3.el7.x86_64 is excluded
  - package containerd.io-1.2.4-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.5-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.6-3.3.el7.x86_64 is excluded
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

根据这篇博客的提示,手动安装 containerd.io 可以解决问题
https://medium.com/@anuketjain007/installation-of-docker-fails-on-centos-8-with-error-package-containerd-io-f7a338b34a71

yum install -y https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
Docker CE Stable - x86_64                        88 kB/s | 3.5 kB     00:00
containerd.io-1.2.6-3.3.el7.x86_64.rpm           18 MB/s |  26 MB     00:01
Package containerd.io-1.2.6-3.3.el7.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete

然后再安装docker 即可

# yum install docker-ce docker-ce-cli
Last metadata expiration check: 0:12:41 ago on Wed 22 Jul 2020 06:39:13 AM UTC.
Package docker-ce-3:19.03.12-3.el7.x86_64 is already installed.
Package docker-ce-cli-1:19.03.12-3.el7.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!

装好之后,启动服务

[root@ip-172-16-2-231 /]# systemctl enable docker
[root@ip-172-16-2-231 /]# systemctl start docker
[root@ip-172-16-2-231 /]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor pres>
   Active: active (running) since Wed 2020-07-22 05:59:14 UTC; 53min ago
     Docs: https://docs.docker.com
 Main PID: 3240 (dockerd)
    Tasks: 15
   Memory: 90.6M
   CGroup: /system.slice/docker.service

然后做个小测试,生成一个容器

docker run -d -p 8080:80 nginx

AWS的SG组上放行8080端口

Docker 学习笔记 -  Redhat 8 上面安装Docker

访问 http://ip:8080 可以看见nginx已经工作了

Docker 学习笔记 -  Redhat 8 上面安装Docker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!