Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I install Docker inside an alpine container?

Tags:

How can I install Docker inside an alpine container and run docker images? I could install, but could not start docker and while running get "docker command not found error".

like image 944
Subit Das Avatar asked Jan 08 '19 20:01

Subit Das


People also ask

Can I install docker inside a container?

To run docker inside docker, all you have to do it just run docker with the default Unix socket docker. sock as a volume. Just a word of caution: If your container gets access to docker. sock , it means it has more privileges over your docker daemon.

Does Alpine image have docker?

Alpine Linux does have a service management system, OpenRC, as an optional extra, but it is not necessary in Docker images. Instead, use the Nginx binary files to run OpenRC via the command line, as it only has one job.

Can I install docker inside VirtualBox?

Docker for Windows uses Microsoft Hyper-V for virtualization, and Hyper-V is not compatible with Oracle VirtualBox. Therefore, you cannot run the two solutions simultaneously. But you can still use docker-machine to create more local VMs by using the Microsoft Hyper-V driver.


2 Answers

Dockerfile for running docker-cli inside alpine

FROM alpine:3.10
RUN apk add --update docker openrc
RUN rc-update add docker boot

Build docker image

docker build -t docker-alpine .

Run container (host and the alipne container will share the same docker engine)

docker run -it -v "/var/run/docker.sock:/var/run/docker.sock:rw" docker-alpine:latest /bin/sh
like image 124
sai anudeep Avatar answered Nov 04 '22 07:11

sai anudeep


All you need is to install Docker CLI in an image based on Alpine and run the container mounting docker.sock. It allows running sibling Docker containers using host's Docker Engine. It is known as Docker-out-of-Docker and is considered a good alternative to running a separate Docker Engine inside a container (aka Docker-in-Docker).

Dockerfile

FROM alpine:3.11

RUN apk update && apk add --no-cache docker-cli

Build the image:

docker build -t alpine-docker .

Run the container mounting the docker.sock (-v /var/run/docker.sock:/var/run/docker.sock):

docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock alpine-docker docker ps

The command above should successfully run docker ps inside the Alpine-based container.

like image 36
Evgeniy Khyst Avatar answered Nov 04 '22 08:11

Evgeniy Khyst