在Alpine容器中放置docker-compose [英] docker-compose inside Alpine container
问题描述
我试图将我的应用程序(代码,Dockerfile和docker-compose脚本)捆绑在一个映像中,以便于部署(入口点将 docker-compose起来
)。我的顶级应用程序映像的Dockerfile看起来像这样
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
当我运行此映像时,似乎dockerd尚未启动 top
结果缺席; docker ps
报告无法通过unix:///var/run/docker.sock连接到Docker守护程序。docker守护程序正在运行吗?
。但是,如果我执行 service docker start
,则返回 *警告:docker已经启动。为了使Docker在Alpine容器中正常工作,我需要做些特别的事情吗?
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?
推荐答案
Docker由docker守护程序组成,谁运行用于与守护程序交互的所有服务和CLI(好的,还有很多其他部分,但这是最重要的)。无论您从 service
命令收到什么消息,安装 docker-compose
都不会安装守护进程。
Docker consists of docker daemon, who runs all services, and CLI, used to interact with daemon (ok, there are lots of other parts, but these are most important). Installing docker-compose
does not install daemon, regardless of what message you are getting from service
command.
要在容器内使用 docker
,必须使用 docker-in-docker
图片。它称为 docker:dind
。从中继承(而不是 alpine
)并享受。
To use docker
inside container, you have to use docker-in-docker
image. It is called docker:dind
. Inherit from it (instead of alpine
) and enjoy.
但在阅读这篇文章,解释了为什么这不是一个好主意,以及在容器内部使用docker的其他方法(提示:您可以调用主机的docker容器中的守护进程,只需安装 /var/run/docker.sock:/var/run/docker.sock
套接字)。
But before read this article, which explains why it is not a great idea and what are other ways to use docker inside container (tip: you can call host's docker daemon from inside container with just mounting /var/run/docker.sock:/var/run/docker.sock
socket).
这篇关于在Alpine容器中放置docker-compose的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!