How to deploy a docker image automatically?

Hi Community,

I’ve not found in the documentation how i can deploy a docker image from a private registry.
I’ve set up a pipeline which builds a docker image and pushes it via docker plugin to my registry.
What i want to achieve is a automated deployment when master branch is pushed through git.
Here is my .drone.yml:

kind: pipeline
type: docker
name: build drone demo
steps:
  - name: build
    image: plugins/docker
    settings:
      username:
        from_secret: REGISTRY_USER
      password:
        from_secret: REGISTRY_PASSWORD
      storage_driver: vfs
      registry: my_registry
      repo: my_registry/test/drone
      tags:
        - latest

  - name: deploy
    pull: if-not-exists
    image: my_registry/test/drone
    settings:
      username:
        from_secret: REGISTRY_USER
      password:
        from_secret: REGISTRY_PASSWORD
    commands:
      - docker run -d -p 4444:80 --name drone-test my_registry/test/drone

image_pull_secrets:
- dockerconfig

When I pull the image and run the docker run-command, works fine. Drone just give me this error:

docker run -d -p 4444:80 --name drone-test my_registry/test/drone
/usr/drone/bin/init: line 17: docker: not found

I’ve no clue what this means and where to check for more detailed logs.

Thanks for the help and pointing to a documentation is highly appreciated!

cheers!

line 17: docker: not found

The commands in your pipeline step are executed inside the specified docker image (this means, per your example, docker run is executed inside the my_registry/test/drone container). The above error therefore indicates you are attempting to execute a docker command inside a container that does not have docker installed.

You could consider using:

Oh, I see. Thanks for pointing out this!
So then is there no solution to deploy automatically a previous build Docker image from a regestry with Drone?

This is basically what i want. So there is no Solution with Drone?

You could get it working as well with a docker-in-docker image or with a drone exec pipeline.

From a security point of view, I would not recommend doing so. Allowing docker to run from inside a drone pipeline basically allows root access. That’s why you have to set a repo to trusted for it to work (for doid). I would also immediately set the protected mode which requires a signature on your pipeline.

1 Like

@bradrydzewski
@johanvdw
Thank you for sharing your knowledge with the community!
Very appreciated!