# Adding (self signed) certificates

**URL:** <https://forums.docker.com/t/adding-self-signed-certificates/9761>\
**Category:** Docker Desktop\
**Tags:** macos\
**Created:** [April 21, 2016, 6:42pm UTC](https://forums.docker.com/t/adding-self-signed-certificates/9761 "2016-04-21T18:42:55Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![gesellix](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/gesellix/32/6950_2.png) [@gesellix](https://forums.docker.com/u/gesellix)\
**Post date:** [April 21, 2016, 6:42pm UTC](https://forums.docker.com/t/adding-self-signed-certificates/9761/1 "2016-04-21T18:42:55Z")

</div>

Hi,

I’d like to share an idea to configure the Daemon with own or self signed certificates.

Most forum posts more or less state that we currently cannot use self signed certificates (see [Running an insecure registry --insecure-registry](https://forums.docker.com/t/running-an-insecure-registry-insecure-registry/8159) or [Private docker registry with self signed certificate](https://forums.docker.com/t/private-docker-registry-with-self-signed-certificate/9522)). I wonder if it would make sense to manually copy them into the Hyper-V VM like this:

1. (on your host)  
move the certificates to a directory somewhere in `/Users/...`. We’ll be able to copy files from there into the VM as it will already be mounted by Docker.
2. (on your host) attach to the TTY:  
`screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty`
3. (inside the vm) copy the certificates into the vm:  
`mkdir -p /etc/docker/certs.d/mydomain.com:5000 && cp /Users/.../certs/domain.crt /etc/docker/certs.d/mydomain.com/ca.crt`
4. (inside the vm) restart Docker:  
`service docker restart`

AFAIK changes inside the VM will be removed when restarting the Docker.app. But would the idea work in general? I only had some minutes to give it a try, but only with `CN=docker.local`, which didn’t work, since it doesn’t seem to be resolved from inside the VM.

Any feedback is appreciated!

---

<div class="post-metadata">

**Author:** ![metafour](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/metafour/32/8711_2.png) [@metafour](https://forums.docker.com/u/metafour)\
**Post date:** [April 25, 2016, 11:44pm UTC](https://forums.docker.com/t/adding-self-signed-certificates/9761/2 "2016-04-25T23:44:09Z")

</div>

I run a private registry with a self-signed root CA that uses S3 as the storage backend with the default of doing a redirect enabled.

In addition to doing the above steps I also had to symlink the ca-certificates.crt file into the directory created in step 3 so that the default trusted certs are also available due to the redirect to the storage backend that occurs. Without this, the layers won’t actually download but retry for a few times and then move on to the next layer until all the layers have been tried and the pull will fail indicating it can’t find the image in the registry.

Here’s the command I used to fix this:

`ln -s /etc/ssl/certs/ca-certificates.crt /etc/docker/certs.d/mydomain.com:5000/ca-certificates.crt`

---

<div class="post-metadata">

**Author:** ![owehrens](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/owehrens/32/8977_2.png) [@owehrens](https://forums.docker.com/u/owehrens)\
**Post date:** [April 27, 2016, 6:40am UTC](https://forums.docker.com/t/adding-self-signed-certificates/9761/3 "2016-04-27T06:40:41Z")

</div>

Hi,

I did so as Tobias suggested and I could push an image to a private TLS enabled registry.  
Yes, after restarting Docker for Mac Beta I need to do the above steps again.

Thanks for the idea.

Oliver

---

<div class="post-metadata">

**Author:** ![rogerw](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/rogerw/32/6818_2.png) [@rogerw](https://forums.docker.com/u/rogerw)\
**Post date:** [May 2, 2016, 8:38am UTC](https://forums.docker.com/t/adding-self-signed-certificates/9761/4 "2016-05-02T08:38:01Z")

</div>

When I try this I get prompted for a “docker login” and a password and I cannot get any further without the correct combination. Any idea what that is?

OS X: version 10.11.2 (build: 15C50)  
Docker.app: version v1.11.0-beta9

---

<div class="post-metadata">

**Author:** ![gesellix](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/gesellix/32/6950_2.png) [@gesellix](https://forums.docker.com/u/gesellix)\
**Post date:** [May 2, 2016, 9:48am UTC](https://forums.docker.com/t/adding-self-signed-certificates/9761/5 "2016-05-02T09:48:25Z")

</div>

User: root  
Password none.

---

<div class="post-metadata">

**Author:** ![ebergfur](https://avatars.discourse-cdn.com/v4/letter/e/db5fbb/32.png) [@ebergfur](https://forums.docker.com/u/ebergfur)\
**Post date:** [May 11, 2016, 5:34am UTC](https://forums.docker.com/t/adding-self-signed-certificates/9761/6 "2016-05-11T05:34:39Z")

</div>

I can confirm that this work around works. It would be great if this could be streamlined better or at least persisted between restarts

---

<div class="post-metadata">

**Author:** ![gesellix](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/gesellix/32/6950_2.png) [@gesellix](https://forums.docker.com/u/gesellix)\
**Post date:** [May 11, 2016, 5:55am UTC](https://forums.docker.com/t/adding-self-signed-certificates/9761/7 "2016-05-11T05:55:40Z")

</div>

It can be streamlined a little bit by using a container with volumes/mounts to /User and /etc. Inside that container you can perform the cp command. You still need to reload the deamon afterwards, which means you still have to attach to the VM via screen :-/

---

<div class="post-metadata">

**Author:** ![gesellix](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/gesellix/32/6950_2.png) [@gesellix](https://forums.docker.com/u/gesellix)\
**Post date:** [May 13, 2016, 10:23pm UTC](https://forums.docker.com/t/adding-self-signed-certificates/9761/8 "2016-05-13T22:23:16Z")

</div>

Like mentioned above: you can use a container to copy from your host system into the Docker VM. This is how it worked for me: [https://github.com/gesellix/inject-docker-certs](https://github.com/gesellix/inject-docker-certs)

The linked project gives you:

- a simple script to generate CA and server certificates
- a docker image to perform the copy from your host into the VM

Interesting fact: I didn’t need to restart the Docker daemon anymore, so I’m not sure if that’s an improvement of the recently updated beta.

---

<div class="post-metadata">

**Author:** ![eslam](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/eslam/32/7977_2.png) [@eslam](https://forums.docker.com/u/eslam)\
**Post date:** [May 14, 2016, 10:04pm UTC](https://forums.docker.com/t/adding-self-signed-certificates/9761/9 "2016-05-14T22:04:30Z")

</div>

I’ve tried to add the root certificate and the intermediate one, but it didn’t work, any ideas

---

<div class="post-metadata">

**Author:** ![gesellix](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/gesellix/32/6950_2.png) [@gesellix](https://forums.docker.com/u/gesellix)\
**Post date:** [May 14, 2016, 10:15pm UTC](https://forums.docker.com/t/adding-self-signed-certificates/9761/10 "2016-05-14T22:15:36Z")

</div>

@eslam do you have details?  
The root certificate should be appended to `/etc/ssl/certs/ca-certificates.crt`, similar to what @metafour mentioned above. The intermediate cert should also be included in the certificate file you put into Docker’s `.../certs.d/.../` directory.  
What exactly didn’t work? Any error message?

---

<div class="post-metadata">

**Author:** ![jonatanblue](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@jonatanblue](https://forums.docker.com/u/jonatanblue)\
**Post date:** [May 17, 2016, 10:32am UTC](https://forums.docker.com/t/adding-self-signed-certificates/9761/11 "2016-05-17T10:32:10Z")

</div>

Nice one! Thanks for sharing.

I can confirm that this workaround works on Docker for Mac:  
`Version 1.11.1-beta11 (build: 6974)`  
`OS X El Capitan 10.11.4`

I have two CA certs - one root and one intermediate CA for issuing the registry cert.

I had to put the root CA cert and the intermediate CA cert in the same file (the root first, if that makes a difference):  
`/etc/docker/certs.d/mydomain.com/ca.crt`

---

<div class="post-metadata">

**Author:** ![eslam](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/eslam/32/7977_2.png) [@eslam](https://forums.docker.com/u/eslam)\
**Post date:** [May 17, 2016, 3:52pm UTC](https://forums.docker.com/t/adding-self-signed-certificates/9761/12 "2016-05-17T15:52:59Z")

</div>

I’ve managed to get it working by just appending the root certificate and the intermediates to the end of /etc/ssl/certs/ca-certificates.crt file.

The only issue I’m trying to workaround is that this file is volatile, everytime I restart docker my appended content will be removed.

Any ideas

---

<div class="post-metadata">

**Author:** ![gesellix](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/gesellix/32/6950_2.png) [@gesellix](https://forums.docker.com/u/gesellix)\
**Post date:** [May 17, 2016, 3:58pm UTC](https://forums.docker.com/t/adding-self-signed-certificates/9761/13 "2016-05-17T15:58:38Z")

</div>

> The only issue I’m trying to workaround is that this file is volatile, everytime I restart docker my appended content will be removed.

@eslam AFAIK that’s a constraint which cannot be solved at the moment. The maintainers know about that issue, but are probably working on getting other mainstream features completed. I guess that’s ok for a beta, and the containerized solution is a single command you could probably automate somehow - maybe there’s a OS X feature to automatically start another command after an application has been started?

---

<div class="post-metadata">

**Author:** ![eslam](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/eslam/32/7977_2.png) [@eslam](https://forums.docker.com/u/eslam)\
**Post date:** [May 17, 2016, 4:36pm UTC](https://forums.docker.com/t/adding-self-signed-certificates/9761/14 "2016-05-17T16:36:33Z")

</div>

In docker-toolbox, I used to add all the self-singed certificates in /var/lib/boot2docker/certs of the docker-machine I have and restart the docker-machine.  
This doesn’t work for the current docker for mac.  
However, I’ve kept my certificates and a small script “to append certificates and restart docker service” in /var/lib/boot2docker/certs dir.  
I’ve restarted docker many times, certs and my script still there.  
The weird issue is that I’ve to restart docker service, whereas I’m using the latest beta version 1.11.1

---

<div class="post-metadata">

**Author:** ![nmiyake](https://avatars.discourse-cdn.com/v4/letter/n/43a26b/32.png) [@nmiyake](https://forums.docker.com/u/nmiyake)\
**Post date:** [May 25, 2016, 5:57am UTC](https://forums.docker.com/t/adding-self-signed-certificates/9761/15 "2016-05-25T05:57:22Z")

</div>

Thanks for documenting this – wanted to confirm that this works for me. Connecting to the Docker for Mac VM and being able to append my root certificate to `/etc/ssl/certs/ca-certificates.crt` worked like a charm!

Hope that the story for adding trusted certificates to Docker improves in the final release!

---

<div class="post-metadata">

**Author:** ![drewish](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/drewish/32/10461_2.png) [@drewish](https://forums.docker.com/u/drewish)\
**Post date:** [May 27, 2016, 6:59pm UTC](https://forums.docker.com/t/adding-self-signed-certificates/9761/16 "2016-05-27T18:59:23Z")

</div>

I also found I didn’t need to restart the service… in fact when I’d try to restart it it would never succeed.

---

<div class="post-metadata">

**Author:** ![drewish](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/drewish/32/10461_2.png) [@drewish](https://forums.docker.com/u/drewish)\
**Post date:** [June 2, 2016, 10:01pm UTC](https://forums.docker.com/t/adding-self-signed-certificates/9761/17 "2016-06-02T22:01:07Z")

</div>

I ended up coming up with this bash script to automate the cert installation:

```
#!/bin/bash

# This assumes the cert is in the same directory as the script
source="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# You'll want to update this to reflect your repo's host and port
destination=/etc/docker/certs.d/example.net:1234

# Send a new line to wake it up, then login as root with a blank password
cat <<HERE > ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty

root

HERE

# Give it a second to get logged in, copy the cert and log back out
cat <<HERE > ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
mkdir -p $destination
cp $source/My_Cert.crt $destination
exit

HERE
```

---

<div class="post-metadata">

**Author:** ![gesellix](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/gesellix/32/6950_2.png) [@gesellix](https://forums.docker.com/u/gesellix)\
**Post date:** [June 6, 2016, 3:04pm UTC](https://forums.docker.com/t/adding-self-signed-certificates/9761/18 "2016-06-06T15:04:30Z")

</div>

> [@drewish](#):
>
> I also found I didn’t need to restart the service… in fact when I’d try to restart it it would never succeed.

Do you mean the restart doesn’t work?

---

<div class="post-metadata">

**Author:** ![drewish](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/drewish/32/10461_2.png) [@drewish](https://forums.docker.com/u/drewish)\
**Post date:** [June 6, 2016, 4:55pm UTC](https://forums.docker.com/t/adding-self-signed-certificates/9761/19 "2016-06-06T16:55:17Z")

</div>

correct, it would never start back up.

---

<div class="post-metadata">

**Author:** ![klippx](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/klippx/32/11167_2.png) [@klippx](https://forums.docker.com/u/klippx)\
**Post date:** [June 9, 2016, 4:34pm UTC](https://forums.docker.com/t/adding-self-signed-certificates/9761/20 "2016-06-09T16:34:23Z")

</div>

This solution worked for me: [https://github.com/klippx/inject-docker-certs](https://github.com/klippx/inject-docker-certs)

[Next page](https://forums.docker.com/t/adding-self-signed-certificates/9761.md?page=2)
