How can I install Docker inside an alpine container?

会有一股神秘感。 提交于 2020-12-23 03:45:17

问题


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".


回答1:


Dockerfile for running docker 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

docker run -it -v "/var/run/docker.sock:/var/run/docker.sock:rw" docker-alpine:latest /bin/sh



回答2:


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.



来源:https://stackoverflow.com/questions/54099218/how-can-i-install-docker-inside-an-alpine-container

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!