---
title: "alpine linux下安装docker"
author: "jaychang"
date: "2017-12-09T15:46:32Z"
tags: []
categories: ["开源软件"]
slug: "alpine-linux-docker"
draft: false
lastmod: "2017-12-09T15:49:36Z"
id: 2404241
url: "https://jaychang.iteye.com/blog/2404241"
---

## Installation

Run apk add docker  
to install Docker on Alpine Linux.  
The Docker package is in the 'Community' repository, so if the **apk add** fails with **unsatisfiable constraints**, you need to edit the **/etc/apk/repositories** file to add (or uncomment) a line like:  
[http://dl-6.alpinelinux.org/alpine/edge/community](https://link.jianshu.com?t=http%3A%2F%2Fdl-6.alpinelinux.org%2Falpine%2Fedge%2Fcommunity)

 

强烈推荐使用中科大alipine linux软件源（http://mirrors.ustc.edu.cn/help/alpine.html#id1）

 

可以使用如下命令：

```
sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
```

或者：  
添加  
[http://dl-cdn.alpinelinux.org/alpine/edge/main](https://link.jianshu.com/?t=http%3A%2F%2Fdl-cdn.alpinelinux.org%2Falpine%2Fedge%2Fmain)  
[http://dl-cdn.alpinelinux.org/alpine/edge/community](https://link.jianshu.com/?t=http%3A%2F%2Fdl-cdn.alpinelinux.org%2Falpine%2Fedge%2Fcommunity)

apk update  
apk add docker

**To start the Docker daemon at boot, run:**  
rc-update add docker boot

**Then to start the Docker daemon manually, run:**  
service docker start

\*\*Note: \*\*You'll need to disable some kernel security flags in order to build images:  
sysctl -w kernel.grsecurity.chroot\_deny\_chmod=0

sysctl -w kernel.grsecurity.chroot\_deny\_mknod=0

For more information, have a look at the [corresponding Github issue](https://link.jianshu.com?t=https%3A%2F%2Fgithub.com%2Fdocker%2Fdocker%2Fissues%2F20303).

 

 

然后更新下docker 镜像中心的地址，强烈建议用中科大的https://lug.ustc.edu.cn/wiki/mirrors/help/docker

## 使用说明

新版的 Docker 使用 /etc/docker/daemon.json（Linux） 或者 %programdata%\\docker\\config\\daemon.json（Windows） 来配置 Daemon。

请在该配置文件中加入（没有该文件的话，请先建一个）：

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

Docker Daemon configuration file 文档： [https://docs.docker.com/engine/reference/commandline/dockerd/#/daemon-configuration-file](https://docs.docker.com/engine/reference/commandline/dockerd/#/daemon-configuration-file "https://docs.docker.com/engine/reference/commandline/dockerd/#/daemon-configuration-file")

Docker for Windows 文档: [https://docs.docker.com/docker-for-windows/#/docker-daemon](https://docs.docker.com/docker-for-windows/#/docker-daemon "https://docs.docker.com/docker-for-windows/#/docker-daemon")

* * *

以下是一些过时的配置方法

在 Docker 的启动参数中加入:

```
--registry-mirror=https://docker.mirrors.ustc.edu.cn
```

Ubuntu 用户（包括使用 systemd 的 Ubuntu 15.04）可以修改 /etc/default/docker 文件，加入如下参数：

```
DOCKER_OPTS="--registry-mirror=https://docker.mirrors.ustc.edu.cn"
```

其他 systemd 用户可以通过执行 sudo systemctl edit docker.service 来修改设置, 覆盖默认的启动参数:

```
[Service]
ExecStart=
ExecStart=/usr/bin/docker -d -H fd:// --registry-mirror=https://docker.mirrors.ustc.edu.cn
```