yum安装docker完整步骤

2023-06-26 18:18
28
0

yum安装docker完整步骤

 

1.环境准备
[root@localhost ~]# getenforce    #关闭selinux
Disabled
[root@localhost ~]# iptables -F  #清空规则
[root@localhost ~]# systemctl stop firewalld   #关闭防火墙
[root@localhost ~]# cat <<EOF > /etc/sysctl.d/docker.conf #开启流量转发
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0
net.ipv4.ip_forward = 1
EOF

[root@localhost ~]# modprobe br_netfilter   #加载参数,配置文件
[root@localhost ~]# sysctl -p /etc/sysctl.d/docker.conf 
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0
net.ipv4.ip_forward = 1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2.yum安装
#下载阿里源repo文件

[root@localhost ~]# curl -o /etc/yum.repos.d/Centos-7.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2318  100  2318    0     0  15491      0 --:--:-- --:--:-- --:--:-- 15557
#docker repo文件
[root@localhost ~]# curl -o /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2081  100  2081    0     0  19671      0 --:--:-- --:--:-- --:--:-- 19819
1
2
3
4
5
6
7
8
9
#检查yum源

[root@localhost ~]# yum makecache
1
#查看yun有哪些docker-ce的版本

[root@localhost ~]# yum list docker-ce --showduplicates | sort -r
1
#安装docker

[root@localhost ~]# yum -y install  docker-ce-20.10.6
1
#配置阿里云的镜像加速器
https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors

#修改daemon配置文件/etc/docker/daemon.json来使用加速器

[root@localhost ~]# mkdir -p /etc/docker
[root@localhost ~]# tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://p0pgcdb3.mirror.aliyuncs.com"]
}
EOF

[root@localhost ~]# 
1
2
3
4
5
6
7
8
#加载配置文件,重启服务

[root@localhost ~]# systemctl daemon-reload 
[root@localhost ~]# systemctl restart docker
1
2
#补充

docker pull 名称                                        #拉取镜像
[root@localhost ~]# docker pull mysql                #示例


docker images                                         #查看镜像
[root@localhost ~]# docker images                    #示例
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
redis        latest    ddcca4b8a6f0   6 days ago     105MB
nginx        latest    dd34e67e3371   6 days ago     133MB
mysql        latest    5a4e492065c7   6 days ago     514MB
centos       latest    300e315adb2f   8 months ago   209MB


docker run -it 镜像:版本号 bash                         #进入镜像。不加版本号默认最新的版本
[root@localhost ~]# docker run -it redis bash        #示例
root@8e840d63fbdb:/data# 


docker rm 进程ID号                                     #停止该进程服务
[root@localhost ~]# docker rm 5ea                      #示例
5ea
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

docker rmi 镜像                                         #删除镜像
[root@localhost ~]# docker rmi centos                #示例
Untagged: centos:latest
Untagged: centos@sha256:5528e8b1b1719d34604c87e11dcd1c0a20bedf46e83b5632cdeac91b8c04efc1
Deleted: sha256:300e315adb2f96afe5f0b2780b87f28ae95231fe3bdd1e16b9ba606307728f55
Deleted: sha256:2653d992f4ef2bfd27f94db643815aa567240c37732cae1405ad1c1309ee9859
[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED      SIZE
redis        latest    ddcca4b8a6f0   6 days ago   105MB
nginx        latest    dd34e67e3371   6 days ago   133MB


docker ps                                            #显示当前正在运行的镜像容器


docker image save 镜像 > 所需导出路径                    #导出镜像到某路径
[root@localhost ~]# docker image save centos > /opt/centos.tgz    #示例


docker image load -i /路径/镜像压缩包
[root@localhost ~]# docker image load -i /opt/centos.tgz        #示例


docker run -d --name 名字 -p 镜像内端口:本机端口 镜像
[root@localhost ~]# docker run -d --name q_nginx -p 81:80 nginx


docker commit 进程ID 新命名                            #提交容器
[root@localhost ~]# docker commit a620c3df8eea my_centos/vim     #示例    

docker inspect 进程ID                                    #查看详细信息
 [root@localhost html]# docker inspect d067d8c8b387     #示例
[
    {
        "Id": "d067d8c8b3879a1c6ffd7d8b4d6f765c4fbaf990ec178b50fc689251716b355f",
        "Created": "2021-08-26T07:37:06.923444949Z",
        "Path": "/docker-entrypoint.sh",
        "Args": [
            "bash"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 8122,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2021-08-26T07:37:07.17583544Z",
            "FinishedAt": "0001-01-01T00:00:00Z"

 
原文链接:https://blog.csdn.net/weixin_48724266/article/details/119823179

全部评论