Unable to push image to custom docker repository

The content of .drone.yml:

pipeline:
  docker:
    image: plugins/docker
    repo: registry.halfakop.ru:5000/tbftpro/swagger
    registry: registry.halfakop.ru:5000
    secrets: [ registry_username, registry_password ]
    when:
      branch: master
      status: success

The error:

+ /usr/local/bin/docker tag ff83ce1877c5487fe3491faedc195aad77042fdc registry.halfakop.ru:5000/tbftpro/swagger:latest
+ /usr/local/bin/docker push registry.halfakop.ru:5000/tbftpro/swagger:latest
The push refers to repository [registry.halfakop.ru:5000/tbftpro/swagger]
Get https://registry.halfakop.ru:5000/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
time="2018-10-31T20:13:27Z" level=fatal msg="exit status 1"

It seems the docker container has no network at this time. How to fix this issue?
How to debug this container?

I cannot speak to your network configuration or network problems, but I can see that secrets are incorrect. The docker plugin expects secrets named docker_username and docker_password [1].

[1] http://docs.drone.io/secrets-not-working/

I have changed secrets names to docker_username and docker_password and got:
time="2018-11-01T05:43:10Z" level=fatal msg="Error authenticating: exit status 1"

But the following works fine:

curl -X GET -u $DOCKER_USERNAME:$DOCKER_PASSWORD https://registry.halfakop.ru:5000/v2/

How to debug the container? How to use drone CLI?

$ docker ps | grep drone
a3987e1c0c46        drone/agent:0.8                    "/bin/drone-agent"       10 hours ago        Up 10 hours (healthy)   3000/tcp devenv_drone-agent_1
30ef1fa90a3d        drone/drone:0.8                    "/bin/drone-server"      10 hours ago        Up 10 hours             80/tcp, 443/tcp, 0.0.0.0:9000->9000/tcp, 0.0.0.0:9080->8000/tcp devenv_drone-server_1

$ docker exec -it devenv_drone-server_1 sh
OCI runtime exec failed: exec failed: container_linux.go:348: starting container process caused "exec: \"sh\": executable file not found in $PATH": unknown

$ docker exec -it devenv_drone-server_1 drone
OCI runtime exec failed: exec failed: container_linux.go:348: starting container process caused "exec: \"drone\": executable file not found in $PATH": unknown

I have found that the following config fails on custom certificate:

pipeline:
  docker:
    image: plugins/docker
    registry: registry.halfakop.ru:5000
    repo: registry.halfakop.ru:5000/tbftpro/swagger
    # secrets: [ docker_username, docker_password ]
    environment:
      - DOCKER_LAUNCH_DEBUG=true
    when:
      branch: master
      status: success
    debug: true
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

Result:

+ /usr/local/bin/docker push registry.halfakop.ru:5000/tbftpro/swagger:latest
The push refers to repository [registry.halfakop.ru:5000/tbftpro/swagger]
Get https://registry.halfakop.ru:5000/v2/: x509: certificate signed by unknown authority
time="2018-11-01T08:14:23Z" level=fatal msg="exit status 1"

The question is how to add custom certificate to the docker image?

Reading:

I have added custom CA to the docker host:

cp halfakop.pem /usr/local/share/ca-certificates/halfakop.crt
update-ca-certificates

And modified the .compose.yml:

environment:
  - DRONE_VOLUME=/etc/ssl/certs:/etc/ssl/certs

and restarted the containers.

Result:

+ /usr/local/bin/docker push registry.halfakop.ru:5000/tbftpro/swagger:latest
The push refers to repository [registry.halfakop.ru:5000/tbftpro/swagger]
Get https://registry.halfakop.ru:5000/v2/: x509: certificate signed by unknown authority
time="2018-11-01T08:14:23Z" level=fatal msg="exit status 1"

And modified the .drone.yml:

registry: registry.halfakop.ru:5000
insecure: true

The same result.

:frowning:

SOLVED

To access the registry you should setup docker host:

  • add CA.pem into /etc/docker/{hostname}:{port}/ca.pem and restart Docker
  • add CA.pem into /usr/local/share/ca-certificates/halfakop.crt and update-ca-certificates

Then make docker login {registry} with your credential and all works fine!