woodpecker/doc/setup/docker.md

92 lines
2.9 KiB
Markdown
Raw Normal View History

2015-07-11 00:40:03 +00:00
# Docker
2015-07-11 00:40:03 +00:00
Drone uses the local Docker daemon (at `unix:///var/run/docker.sock`) to execute your builds with 1x concurrency. This section describes how to customize your Docker configuration and concurrency settings using the `DOCKER_*` environment variables.
2015-07-11 00:40:03 +00:00
Configure a single Docker host (1x build concurrency):
```bash
2015-07-07 04:13:50 +00:00
DOCKER_HOST="unix:///var/run/docker.sock"
2015-07-11 00:40:03 +00:00
```
## Concurrency
Configure Drone to run multiple, concurrent builds by increasing the number of registered Docker hosts. Each `DOCKER_HOST_*` environment variable will increase concurrency by 1.
Configure multiple Docker hosts (4x build concurrency):
```bash
2015-07-07 04:13:50 +00:00
DOCKER_HOST_1="unix:///var/run/docker.sock"
DOCKER_HOST_2="unix:///var/run/docker.sock"
DOCKER_HOST_3="unix:///var/run/docker.sock"
2015-07-11 00:40:03 +00:00
DOCKER_HOST_4="unix:///var/run/docker.sock"
2015-07-07 04:13:50 +00:00
```
2015-07-11 00:40:03 +00:00
Configure a single, external Docker host (1x build concurrency):
```bash
2015-07-11 00:40:03 +00:00
DOCKER_HOST="tcp://1.2.3.4:2376"
2015-07-11 00:40:03 +00:00
DOCKER_CA="/path/to/ca.pem"
DOCKER_CERT="/path/to/cert.pem"
DOCKER_KEY="/path/to/key.pem"
```
2015-07-11 00:40:03 +00:00
Configure multiple, external Docker hosts (4x build concurrency using 2 remote servers):
```bash
2015-07-11 00:40:03 +00:00
DOCKER_HOST_1="tcp://1.2.3.4:2376"
DOCKER_HOST_2="tcp://1.2.3.4:2376"
2015-07-11 00:40:03 +00:00
DOCKER_HOST_3="tcp://4.3.2.1:2376"
DOCKER_HOST_4="tcp://4.3.2.1:2376"
2015-07-11 00:40:03 +00:00
DOCKER_CA="/path/to/ca.pem"
DOCKER_CERT="/path/to/cert.pem"
DOCKER_KEY="/path/to/key.pem"
```
2015-07-11 00:40:03 +00:00
## Remote Servers
Connecting to remote Docker servers requires TLS authentication for security reasons. You will therefore need to generate your own self-signed certificates. For convenience, we've created the following gist to help generate a certificate: https://gist.github.com/bradrydzewski/a6090115b3fecfc25280
This will generate the following files:
* ca.pem
2015-07-07 04:13:50 +00:00
* cert.pem
* key.pem
* server-cert.pem
* server-key.pem
2015-07-11 00:40:03 +00:00
Tell Drone where to find the `cert.pem` and `key.pem`:
```bash
2015-07-11 00:40:03 +00:00
DOCKER_CERT="/path/to/cert.pem"
DOCKER_KEY="/path/to/key.pem"
```
When running Drone inside Docker, you'll need to mount the volume containing the certificate:
```bash
2015-07-11 00:40:03 +00:00
docker run
--volume /path/to/cert.pem:/path/to/cert.pem \
--volume /path/to/key.pem:/path/to/key.pem \
```
2015-07-11 00:40:03 +00:00
Tell Docker where to find the certificate files. Install the certificates on every remote machine (in `/etc/ssl/docker/`) and update each Docker configuration file (at `/etc/init/drone-dart.conf`) accordingly:
```bash
# Use DOCKER_OPTS to modify the daemon startup options.
DOCKER_OPTS="--tlsverify --tlscacert=/etc/ssl/docker/ca.pem --tlscert=/etc/ssl/docker/server-cert.pem --tlskey=/etc/ssl/docker/server-key.pem -H=0.0.0.0:2376 -H unix:///var/run/docker.sock"
```
2015-07-11 00:40:03 +00:00
Verify that everything is configured correctly by connecting to a remote Docker server from our Drone server using the following command:
```bash
sudo docker \
--tls \
--tlscacert=/path/to/ca.pem \
--tlscert=/path/to/cert.pem \
--tlskey=/path/to/key.pem \
-H="1.2.3.4:2376" version
```