# Docker for Windows > windows安装docker服务 ## 环境工具下载 - [Docker Desktop Installer.exe](https://desktop.docker.com/win/main/amd64/Docker%20Desktop%20Installer.exe) (windows 环境下运行docker的一款产品) - [wsl_update_x64](https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi) (Linux 内核包) ## 开启相关配置 - 打开任务管理器(Ctrl+Alt+Delete)-> 选择性能 -> CPU ->虚拟化,确认是否已启用 - 开启 Hyper-v,在控制面板打开**程序**,然后点击**启动或关闭windows功能**,找到勾选Hyper-v点击确定 ⚠如果进来没找到Hyper-v功能,就新建一个**Hyper-V.bat**文件,文件内容如下,新建好后,右键以管理员身份运行,开始下载Hyper-v功能(过程可能有点久,务必耐心等待,下载后会提示启动并重启) ```bash pushd "%~dp0" dir /b %SystemRoot%\servicing\Packages\*Hyper-V*.mum >hyper-v.txt for /f %%i in ('findstr /i . hyper-v.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i" del hyper-v.txt Dism /online /enable-feature /featurename:Microsoft-Hyper-V-All /LimitAccess /ALL ``` ## 开始安装服务 - 先安装**wsl_update_X64.msi**,一路下一步next即可完成安装 - 安装完wsl_update_X64.msi后,开始安装**Docker Desktop**(过程有点久,务必耐心等待,安装完会提示关闭重启) - 安装好并启动好docker后,输入:`docker --version`,出现版本号即安装成功 ## 镜像配置 点击设置⚙,找到Docker Engine,添加镜像配置,完成后apply and restart ```dockerfile "registry-mirrors": [ "https://6x1n58x2.mirror.aliyuncs.com", "http://hub-mirror.c.163.com", "https://mirror.baidubce.com" ] ``` # Docker for Linux ## Linux服务器离线安装 下载docker安装包,版本根据自己开发需要进行选择! 下载地址🔗:https://download.docker.com/linux/static/stable/x86_64/ 将下载好的docker-18.06.3-ce.tgz上传到服务器的/data/docker目录下(没有就创建,放一个看空间大一点的位置) - 解压压缩包 ```shell tar -zxvf docker-18.06.3-ce.tgz ``` - 将docker相关命令拷贝到 /usr/bin,方便直接运行命令 ```shell cp docker/* /usr/bin/ ``` - 编写docker.service文件,注意:如下语句末尾需要有个空格,请带上! ```shell vi /etc/systemd/system/docker.service   ``` - docker.service文件内容如下: ```dockerfile [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=10.58.20.199 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 ``` ⚠其中`ExecStart=/usr/bin/dockerd --selinux-enabled=false --insecure-registry=10.51.150.122`,`10.51.150.122`是服务器ip地址,安装部署的时候注意修改这个!!! - 添加文件权限 ```shell chmod +x /etc/systemd/system/docker.service ``` - 重载配置文件 ```shell systemctl daemon-reload ``` - 启动docker ``` systemctl start docker ``` - 设置开机自启 ``` systemctl enable docker.service ``` ⚠docker默认的路径/var/lib/docker,如果这个路径下磁盘空间不够大,经常使用容器的话空间很快就会满了,因此需要修改路径,放到一个空间大一点的路径 - 修改 ```shell vi /etc/systemd/system/docker.service ``` 在`ExecStart=/usr/bin/dockerd` 后面加上 `--graph /data/dockerdata` /data/dockerdata路径不存在的话,就先建一个(保证磁盘空间够大的路径均可) - 重启守护进程和docker ```shell systemctl daemon-reload systemctl restart docker ```