编辑文章 linuxdocker ## 1、用yum源安装 #### 查看是否安装命令 ``` yum list installed | grep docker ``` #### 安装docker命令 ``` yum -y install docker ``` -y表示不询问安装 #### 启动docker命令 ``` systemctl start docker ``` #### 查看docker服务状态 ``` systemctl status docker ``` ## 2、离线安装模式 #### 上传或者下载安装包 ``` wget https://download.docker.com/linux/static/stable/x86_64/docker-18.06.3-ce.tgz ``` #### 解压 复制到目录 ``` tar -zxvf docker-18.06.3-ce.tgz cp docker/* /usr/bin/ ``` #### 在/etc/systemd/system/目录下新增docker.service文件 这样可以将docker注册为service服务 ``` [Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target firewalld.service Wants=network-online.target [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/dockerd --selinux-enabled=false --insecure-registry=127.0.0.1 ExecReload=/bin/kill -s HUP $MAINPID # Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local accounting. LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity # Uncomment TasksMax if your systemd version supports it. # Only systemd 226 and above support this version. #TasksMax=infinity TimeoutStartSec=0 # set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes # kill only the docker process, not all processes in the cgroup KillMode=process # restart the docker process if it exits prematurely Restart=on-failure StartLimitBurst=3 StartLimitInterval=60s [Install] WantedBy=multi-user.target ``` #### 授权 ``` chmod +x /etc/systemd/system/docker.service ``` #### 启动docker 重新加载配置文件 `systemctl daemon-reload` 启动`systemctl start docker` ``` systemctl daemon-reload systemctl start docker ``` #### 设置开机启动 ``` systemctl enable docker.service ``` ## 3、docker命令 #### 进入镜像命令`docker exec -it 89c5b9c81e74 bash` #### 启动容器 `docker run --name nginx` #### 停止容器 `docker stop nginx` #### 删除容器 `docker rm nginx` #### 信息查看 `docker info` ``` [root@10-9-25-182 ~]# docker info Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: 18.06.3-ce Storage Driver: overlay2 Backing Filesystem: xfs Supports d_type: true Native Overlay Diff: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: 468a545b9edcd5932818eb9de8e72413e616e86e runc version: a592beb5bc4c4092b1b1bac971afed27687340c5 init version: fec3683 Security Options: seccomp Profile: default Kernel Version: 4.18.0-147.5.1.el8_1.x86_64 Operating System: CentOS Linux 8 (Core) OSType: linux Architecture: x86_64 CPUs: 1 Total Memory: 1.701GiB Name: 10-9-15-182 ID: 3VIG:ANXE:JRSP:OXY6:QJJG:UI4F:XFFE:GJO2:KRKX:INJJ:NTPN:BTRK Docker Root Dir: /var/lib/docker Debug Mode (client): false Debug Mode (server): false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.1 127.0.0.0/8 Live Restore Enabled: false ``` ## 备注: 如果报错找不到 docker.service ``` Failed to start docker.service: Unit docker.service not found. ``` 参考这篇文章 [https://blog.csdn.net/qiao_xinxin/article/details/114943904](https://blog.csdn.net/qiao_xinxin/article/details/114943904) <h2>1、用yum源安装</h2> <h4>查看是否安装命令</h4> <pre><code>yum list installed | grep docker </code></pre> <h4>安装docker命令</h4> <pre><code>yum -y install docker </code></pre> <p>-y表示不询问安装</p> <h4>启动docker命令</h4> <pre><code>systemctl start docker </code></pre> <h4>查看docker服务状态</h4> <pre><code>systemctl status docker </code></pre> <h2>2、离线安装模式</h2> <h4>上传或者下载安装包</h4> <pre><code>wget https://download.docker.com/linux/static/stable/x86_64/docker-18.06.3-ce.tgz </code></pre> <h4>解压 复制到目录</h4> <pre><code>tar -zxvf docker-18.06.3-ce.tgz cp docker/* /usr/bin/ </code></pre> <h4>在/etc/systemd/system/目录下新增docker.service文件 这样可以将docker注册为service服务</h4> <pre><code>[Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target firewalld.service Wants=network-online.target [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/dockerd --selinux-enabled=false --insecure-registry=127.0.0.1 ExecReload=/bin/kill -s HUP $MAINPID # Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local accounting. LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity # Uncomment TasksMax if your systemd version supports it. # Only systemd 226 and above support this version. #TasksMax=infinity TimeoutStartSec=0 # set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes # kill only the docker process, not all processes in the cgroup KillMode=process # restart the docker process if it exits prematurely Restart=on-failure StartLimitBurst=3 StartLimitInterval=60s [Install] WantedBy=multi-user.target </code></pre> <h4>授权</h4> <pre><code>chmod +x /etc/systemd/system/docker.service </code></pre> <h4>启动docker</h4> <p>重新加载配置文件 <code>systemctl daemon-reload</code></p> <p>启动<code>systemctl start docker</code></p> <pre><code>systemctl daemon-reload systemctl start docker </code></pre> <h4>设置开机启动</h4> <pre><code>systemctl enable docker.service </code></pre> <h2>3、docker命令</h2> <h4>进入镜像命令<code>docker exec -it 89c5b9c81e74 bash</code></h4> <h4>启动容器 <code>docker run --name nginx</code></h4> <h4>停止容器 <code>docker stop nginx</code></h4> <h4>删除容器 <code>docker rm nginx</code></h4> <h4>信息查看 <code>docker info</code></h4> <pre><code>[root@10-9-25-182 ~]# docker info Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: 18.06.3-ce Storage Driver: overlay2 Backing Filesystem: xfs Supports d_type: true Native Overlay Diff: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: 468a545b9edcd5932818eb9de8e72413e616e86e runc version: a592beb5bc4c4092b1b1bac971afed27687340c5 init version: fec3683 Security Options: seccomp Profile: default Kernel Version: 4.18.0-147.5.1.el8_1.x86_64 Operating System: CentOS Linux 8 (Core) OSType: linux Architecture: x86_64 CPUs: 1 Total Memory: 1.701GiB Name: 10-9-15-182 ID: 3VIG:ANXE:JRSP:OXY6:QJJG:UI4F:XFFE:GJO2:KRKX:INJJ:NTPN:BTRK Docker Root Dir: /var/lib/docker Debug Mode (client): false Debug Mode (server): false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.1 127.0.0.0/8 Live Restore Enabled: false </code></pre> <h2>备注:</h2> <p>如果报错找不到 docker.service</p> <pre><code>Failed to start docker.service: Unit docker.service not found. </code></pre> <p>参考这篇文章 <a href="https://blog.csdn.net/qiao_xinxin/article/details/114943904">https://blog.csdn.net/qiao_xinxin/article/details/114943904</a></p> 标题: 分类: 请选择分类(必选) 博客 酷玩 分享 相册 标签: 按 Tab、回车或逗号把输入的文字变成标签;点 × 或在输入框为空时按退格删除;最多 8 个 封面图: 上传图片 建议尺寸 800x400,图片大小不超过 1MB 展开更多设置(关键词、摘要、转载、评论) 关键词: 摘要: 1、用yum源安装 查看是否安装命令 yum list installed | grep docker 安装docker命令 yum -y install docker -y表示不询问安装 启动docker命令 systemctl start... 选项: 是否转载 启用评论 勾选「是否转载」可标注文章来源,原文链接可留空。 正文: 保存修改