I'm attempting to bundle my app (code, Dockerfiles and a docker-compose script) together inside a single image for easy deployment (entrypoint will just docker-compose up). My Dockerfile for this top level app image looks like so
FROM alpine:latest
COPY . /app
RUN apk update && apk add --no-cache docker py-pip openrc && pip install docker-compose
When I run this image, it seems that dockerd hasn't started, being absent from top results; docker ps reports "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
". If however I do service docker start, this returns " * WARNING: docker is already starting". Is there anything special I need to do to get Docker working side of an Alpine container?
If you can't or don't want to inherit from docker:dind as mentioned in grapes answer there is an option to use alpine as a base image and install Docker CLI and Docker Compose.
To keep image small some dependencies can be deleted after Docker Compose installation:
FROM alpine:3.11
RUN apk update && \
apk add --no-cache docker-cli python3 && \
apk add --no-cache --virtual .docker-compose-deps python3-dev libffi-dev openssl-dev gcc libc-dev make && \
pip3 install docker-compose && \
apk del .docker-compose-deps
This image doesn't contain Docker Engine and Docker-in-Dcoker approach has to be used by mounting /var/run/docker.sock from the host
docker run -v /var/run/docker.sock:/var/run/docker.sock <image name>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With