Vignesh k
Vignesh k

Reputation: 151

docker private registry creation fails with following log msg: level=fatal msg="open /home/vignesh/certs/localregistry.crt: no such file or directory"

I am trying to create a private docker registry. Following is the certificate directory and contents:

vignesh@vignesh-ThinkPad-E470:~/certs$ pwd
/home/vignesh/certs
vignesh@vignesh-ThinkPad-E470:~/certs$ ls -l
total 16
drwxr-xr-x 2 vignesh vignesh 4096 Jul 21 08:41 certs
-rwxrwxr-x 1 vignesh vignesh  920 Jul 21 08:41 localregistry.crt
-rwxrwxr-x 1 vignesh vignesh  712 Jul 21 08:41 localregistry.csr
-rwxrwxr-x 1 vignesh vignesh  963 Jul 21 08:41 localregistry.key

When I create the container it gets killed soon after create and status goes from "up" to "restarting"

docker run -d \
 --restart=always \
 --name registry3 \
 -v /home/vignesh/certs:/certs \
 -e REGISTRY_HTTP_ADDR=0.0.0.0:443 \
 -e REGISTRY_HTTP_TLS_CERTIFICATE=/home/vignesh/certs/localregistry.crt \
 -e REGISTRY_HTTP_TLS_KEY=/home/vignesh/certs/localregistry.key \
 -p 443:443 \
 registry:2

vignesh@vignesh-ThinkPad-E470:~/certs$ docker container ls
 CONTAINER ID   IMAGE        COMMAND                  CREATED          STATUS                          PORTS                                             NAMES
 5e165c1c3b08   registry:2   "/entrypoint.sh /etc…"   18 seconds ago   Up 1 second                     0.0.0.0:443->443/tcp, :::443->443/tcp, 5000/tcp   registry3
 vignesh@vignesh-ThinkPad-E470:~/certs$ docker container ls
 CONTAINER ID   IMAGE        COMMAND                  CREATED          STATUS                          PORTS     NAMES
 5e165c1c3b08   registry:2   "/entrypoint.sh /etc…"   19 seconds ago   Restarting (1) 2 seconds ago              registry3
 vignesh@vignesh-ThinkPad-E470:~/certs$ 

On checking the logs, I see following fatal error saying .crt file not found (several other non fatal messages also seen). But I am able to find the .crt file at path shown in message:

vignesh@vignesh-ThinkPad-E470:~/certs$ docker logs 5e165c1c3b08
time="2021-07-21T03:33:03.10806134Z" level=fatal msg="open /home/vignesh/certs/localregistry.crt: no such file or directory"

vignesh@vignesh-ThinkPad-E470:~/certs$ ls -l /home/vignesh/certs/localregistry.crt
-rwxrwxr-x 1 vignesh vignesh 920 Jul 21 08:41 /home/vignesh/certs/localregistry.crt

Could you please help me here.

Thanks,

Vignesh

Upvotes: 0

Views: 1199

Answers (1)

BMitch
BMitch

Reputation: 265130

The process inside the container sees files in the container's mount namespace, not your host. Since you mapped the directory to a different name in the container, you need to use that path:

docker run -d \
 --restart=always \
 --name registry3 \
 -v /home/vignesh/certs:/certs \
 -e REGISTRY_HTTP_ADDR=0.0.0.0:443 \
 -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/localregistry.crt \
 -e REGISTRY_HTTP_TLS_KEY=/certs/localregistry.key \
 -p 443:443 \
 registry:2

Upvotes: 1

Related Questions