Search code examples
dockerdocker-composedocker-in-docker

Building and pushing a docker image from inside a container


Context: I am using repo2docker to build images containing experiments, then to push them to a private registry.

I am dockerizing this whole pipeline (cloning the code of the experiment, building the image, pushing it) with docker-compose.

This is what I tried:

FROM ubuntu:latest

RUN apt-get update && apt-get install -y python3-pip python3-dev git apt-transport-https ca-certificates curl software-properties-common

RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
RUN apt-get update && apt-get install docker-ce --yes
RUN service docker start

# more setup

ENTRYPOINT rqworker -c settings image_build_queue

Then I pass the jobs to the rqworker (the rqworker part works well).

But docker doesn't start in my container. Therefore I can't login to the registry and can't build the image.

(Note that I need docker to run, but I don't need to run containers.)


Solution

  • The solution was to share the host's Docker socket, so the build actually happens on the host.