Create a docker container containing a freshly build application in drone?

Sorry I ask this, but I somehow got stuck searching the forums for a layman’s guide.

I’m writing a c++ application which is kept in a private git repository. Now I want to build this app in a docker/podman container to be able to run it on my server (the same hosting drone).
But I don’t get how to do it. If I use the normal docker pipeline, the app is build. But the result is either dropped or I can upload it to git as a release.

Do I need a Docker-In-Docker (“DID?”) to be able to create a reusable docker container? Do I need another harness toolchain item to do this?

I found so many drone yaml files which did some strange black magic which I wasn’t able to understand, so It would be nice if someone could tell me if drone itself can create resusable containers, and if there’s a simple up-to-date guide on how to do it.

Thanks, and have a nice day
X

There are many ways to build docker images in drone, but I will assume you are attempting to use the docker plugin (since this is the most common option). The purpose of the docker plugin is to build and publish a docker image to a registry. This happens inside a container, using docker-in-docker.

In your case, you want to build and run the docker image on the host machine. The challenge is that Drone steps run inside containers. So if you want to build and run docker images on the host machine, you will need to connect to the docker daemon on the host.

This can be done by mounting the host machine docker socket into your pipeline, so that it is accessible inside your pipeline steps:

kind: pipeline
name: default

steps:
- name: test
  image: docker:dind
  volumes:
  - name: dockersock
    path: /var/run/docker.sock
  commands:
  - docker build -t xplod/my-image
  - docker run -d xplod/my-image

volumes:
- name: dockersock
  host:
    path: /var/run/docker.sock

The above yaml file is pseudo code, adapted from this section of the docs. You will need to modify to meet your exact use case, but hopefully this is enough information to get you started. For example, you will probably need to check and see if the container is already running and stop it.

Thanks for your help. I’ll try this…