Skip to content

Commit c51040b

Browse files
committed
docker: remove insecure tcp://0.0.0.0:2375 configuration
TCP connection without TLS is completely insecure and can easily result in container breakout. Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
1 parent 9c3abb3 commit c51040b

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

docker/content.md

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,22 @@ If you are still convinced that you need Docker-in-Docker and not just access to
1919
## Start a daemon instance
2020

2121
```console
22-
$ docker run --privileged --name some-docker -d %%IMAGE%%:dind
22+
$ docker run --privileged --name some-docker -d -v /daemon-secret:/secret %%IMAGE%%:dind \
23+
dockerd -H tcp://0.0.0.0:2376 --tlsverify --tlscacert /secret/ca.pem --tlscert /secret/cert.pem --tlskey /secret/key.pem
2324
```
2425

2526
**Note:** `--privileged` is required for Docker-in-Docker to function properly, but it should be used with care as it provides full access to the host environment, as explained [in the relevant section of the Docker documentation](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities).
2627

27-
By default, the `dind` variants of this image add `--host=tcp://0.0.0.0:2375` (on top of the explicit default of `--host=unix:///var/run/docker.sock`) in order to allow external containers to access `dockerd` appropriately (as the following examples illustrate). If you use `--network=host` or other methods of sharing network namespaces (such as Kubernetes pods, for example), this might be a security issue. To disable this image behavior, simply override the container command or entrypoint to run `dockerd` directly (`... docker:dind dockerd ...` or `... --entrypoint dockerd docker:dind ...`).
28+
**Warning:** by default, the `dind` variants of this image add `--host=tcp://0.0.0.0:2375` (on top of the explicit default of `--host=unix:///var/run/docker.sock`) in order to allow other containers to access `dockerd` (as the following examples illustrate). If you use `--network=host`, shared network namespaces (as in Kubernetes pods), or otherwise have network access to the container (including containers started within the `dind` instance via their gateway interface), this is a potential security issue (which can lead to access to the host system, for example). To disable this image behavior, simply override the container command or entrypoint to run `dockerd` directly (`... docker:dind dockerd ...` or `... --entrypoint dockerd docker:dind ...`). It is recommended to implement TLS (`... docker:dind dockerd --host tcp://0.0.0.0:2376 --tlsverify ...`) if network access to the `dind` instance is required.
2829

2930
## Connect to it from a second container
3031

32+
`/client-secret` is assumed to contain `ca.pem`, `cert.pem`, and `key.pem` here.
33+
3134
```console
32-
$ docker run --rm --link some-docker:docker %%IMAGE%%:edge version
35+
$ docker run --rm --link some-docker:docker -v /client-secret:/root/.docker \
36+
-e DOCKER_HOST=tcp://docker:2376 -e DOCKER_TLS_VERIFY=1 \
37+
%%IMAGE%%:edge version
3338
Client:
3439
Version: 17.05.0-ce
3540
API version: 1.27 (downgraded from 1.29)
@@ -49,7 +54,9 @@ Server:
4954
```
5055

5156
```console
52-
$ docker run -it --rm --link some-docker:docker %%IMAGE%%:edge sh
57+
$ docker run -it --rm --link some-docker:docker -v /client-secret:/root/.docker %%IMAGE%%:edge sh
58+
/ # export DOCKER_HOST=tcp://docker:2376
59+
/ # export DOCKER_TLS_VERIFY=1
5360
/ # docker version
5461
Client:
5562
Version: 17.05.0-ce
@@ -70,7 +77,9 @@ Server:
7077
```
7178

7279
```console
73-
$ docker run --rm --link some-docker:docker %%IMAGE%% info
80+
$ docker run --rm --link some-docker:docker -v /client-secret:/root/.docker \
81+
-e DOCKER_HOST=tcp://docker:2376 -e DOCKER_TLS_VERIFY=1 \
82+
%%IMAGE%%:edge info
7483
Containers: 0
7584
Running: 0
7685
Paused: 0
@@ -113,6 +122,37 @@ Insecure Registries:
113122
Live Restore Enabled: false
114123
```
115124

125+
## Connect via UNIX socket
126+
127+
If the client and the daemon are running on the same host and you don't want to configure TLS, you can use UNIX socket instead.
128+
129+
```console
130+
$ mkdir /tmp/foo
131+
$ docker run --privileged --name some-docker -d -v /tmp/foo:/var/run %%IMAGE%%:dind dockerd
132+
```
133+
134+
```console
135+
$ docker run --rm -v /tmp/foo:/var/run %%IMAGE%% version
136+
Client:
137+
Version: 17.05.0-ce
138+
API version: 1.28 (downgraded from 1.29)
139+
Go version: go1.7.5
140+
Git commit: 89658be
141+
Built: Fri May 5 15:36:11 2017
142+
OS/Arch: linux/amd64
143+
144+
Server:
145+
Version: 17.04.0-ce
146+
API version: 1.28 (minimum version 1.12)
147+
Go version: go1.8
148+
Git commit: 4845c56
149+
Built: Thu Apr 27 07:51:43 2017
150+
OS/Arch: linux/amd64
151+
Experimental: false
152+
```
153+
154+
To connect to the host daemon:
155+
116156
```console
117157
$ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock %%IMAGE%% version
118158
Client:

0 commit comments

Comments
 (0)