# Docker 安装与启动

## Docker安装与启动

### 安装Docker Docker

官方建议在Ubuntu中安装，因为Docker是基于Ubuntu发布的，而且一般Docker出现的问题Ubuntu是最 先更新或者打补丁的。在很多版本的CentOS中是不支持更新最新的一些补丁包的。

&#x20;由于我们学习的环境都使用的是CentOS，因此这里我们将Docker安装到CentOS上。注意：这里建议安装在 CentOS7.x以上的版本，在CentOS6.x的版本中，安装前需要安装其他很多的环境而且Docker很多补丁不支持更 新。

&#x20;请直接挂载课程配套的Centos7.x镜像&#x20;

（1）yum 包更新到最新

```javascript
sudo yum update
```

（2）安装需要的软件包， yum-util 提供yum-config-manager功能，另外两个是devicemapper驱动依赖的

```
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
```

（3）设置yum源为阿里云

```
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-
ce/linux/centos/docker-ce.repo
```

（4）安装docker

```
sudo yum install docker-ce
```

（5）安装后查看docker版本

```
docker -v
```

### 设置ustc的镜像

ustc是老牌的linux镜像服务提供者了，还在遥远的ubuntu 5.04版本的时候就在用。ustc的docker镜像加速器速度 很快。ustc docker mirror的优势之一就是不需要注册，是真正的公共服务。

&#x20;<https://lug.ustc.edu.cn/wiki/mirrors/help/docker>

编辑该文件：

```
vi /etc/docker/daemon.json
```

在该文件中输入如下内容：

```javascript
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
}
```

### Docker的启动与停止

systemctl 命令是系统服务管理器指令&#x20;

启动docker：

```
systemctl start docker
```

停止docker：

```
systemctl stop docker
```

重启docker：

```
systemctl restart docker
```

查看docker状态：

```
systemctl status docker
```

开机启动：

```
systemctl enable docker
```

查看docker概要信息

```
docker info
```

查看docker帮助文档

```
docker --help
```

## 参考：Docker 安装与镜像

[官方文档](https://docs.docker.com/)

### 安装

<https://docs.docker.com/install/linux/docker-ce/ubuntu/>

[Ubuntu18.04下Docker CE安装](https://www.jianshu.com/p/07e405c01880)

**常见错误**

IPv4forwarding is disabled.Networkingwill not work.

解决办法：

`sudo vi/etc/sysctl.conf`(Linux内核参数配置文件，可在运行时修改某些内核参数，使之永久生效)

加入`net.ipv4.ip_forward=1`

保存并退出后 执行`systemctl restart network`

#### 资料

安装也可以参考[阿里云的文档Docker CE 镜像源站](https://yq.aliyun.com/articles/110806?spm=a2c1q.8351553.0.0.11b720beQRyGTx)

[ubuntu安装docker官方文档](https://docs.docker.com/install/linux/docker-ce/ubuntu/)

#### centos 安装docker

[centos安装docker官方文档](https://docs.docker.com/install/linux/docker-ce/centos/)

## 镜像

地址：<https://hub.docker.com/>

使用阿里云的镜像加速器

1.登录注册

2.选择 容器镜像服务 =》镜像加速器 进行配置

![](https://3836016457-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LfnT3088lKmAdd7HarJ%2F-LfnT7osh8cvAGaoM3Y9%2F-LfnTK9GFgIwVZ6V629k%2Fjiasuqi.png?generation=1558862988667585\&alt=media)

想使用阿里云拉取镜像，则在镜像搜索地方搜索,复制镜像相应的公网地址，使用如下命令：

```
docker pull registry.cn-hangzhou.aliyuncs.com/lxepoo/apache-php5
```

## 资料

[Windows10下安装Docker的步骤](https://www.cnblogs.com/wyt007/p/10656813.html)

```
{
  "registry-mirrors": [
    "https://pypoas5n.mirror.aliyuncs.com"
  ],
  "experimental": true
}
```

[windows10家庭版安装docker踩坑](https://blog.csdn.net/harry5508/article/details/105132207?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.compare\&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.compare)

[Windows10 Docker 下载安装及使用 修改默认存放位置C盘 其它盘符](https://blog.csdn.net/qq_37131345/article/details/106215562)

[windows10 docker 从C盘迁移到其他盘](https://www.cnblogs.com/justblue/p/13202529.html)

```
计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
Professional
```

采用软连的方式更好&#x20;

```
cmd /c mklink /D "C:\ProgramData\Docker" "D:\developer_soft\Docker\ProgramData\Docker"
cmd /c mklink /D "C:\Program Files\Docker" "D:\developer_soft\Docker\Program Files\Docker"
cmd /c mklink /D "C:\ProgramData\DockerDesktop" "D:\developer_soft\Docker\ProgramData\DockerDesktop"
```

重装清除

[在window10上彻底卸载docker](https://www.pythonsky.cn/technical-talk/477.html)

[docker 重装提示 Exising installation is up to date 解决方法](https://blog.csdn.net/qq_35445306/article/details/106242761)

```
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Docker Desktop
```
