Search code examples
dockerdrone.io

Building Docker Images with Drone.io


I'm running my own Drone instance in AWS and I want it to build a docker image and push it to my repo. Drone runs its build environment in a docker container, so I basically want to build docker images from inside a docker container. I found this and saw you can Bind Mount the docker socket. How do I do this with Drone?

docker run -it -v /var/run/docker.sock:/var/run/docker.sock mycompany/buildimage

So I can run docker build from inside my container. Or do you know of another CI tool that I can run my custom script and build docker images.


Solution

  • The answer is outdated, please check @Brad's solution below, use this as reference only

    In your mycompany/buildimage

    Install docker client

    curl https://get.docker.io/builds/Linux/x86_64/docker-latest -o /usr/local/bin/docker
    chmod +x /usr/local/bin/docker 
    

    Then you can run docker build command use docker host environment

    $ docker -H unix:///var/run/docker.sock build .
    

    To make it easy and transparent, usually DOCKER_HOST environment can be set.

    $ export DOCKER_HOST="unix:///var/run/docker.sock"
    $ docker build .
    

    Not familar with the drone installation, but this is the way docker provides