如何在Alpine内部使用Docker/Gitlab CI中的任何Docker图像
我想使用位于其他私人存储库中的Dockerfile构建和测试我的应用程序。 为此,我正在使用Alpine官方Docker Image,其中我运行了一个bash脚本来克隆我的私人仓库并运行Docker来构建Docker Image。这就是我的
.gitlab-ci.yml
的样子。
image: alpine:3.15
stages:
- main
main-job:
stage: main
script:
- apk add --update docker openrc
- rc-update add docker boot
- apk add bash git curl
- bash build.sh $GH_TOKEN $REPO
我在build.sh
中有简单的脚本,
git clone https://${GH_TOKEN}@github.com/${REPO} source
cd source || exit 1
docker container prune --force || true
docker build . --rm --force-rm --compress --no-cache=true --pull --file Dockerfile -t test-app
docker image ls
docker run --privileged --rm -i test-app
但是Docker不会启动和垃圾邮件错误。
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
还尝试使用ubuntu docker中的其他命令尝试
服务start docker
,dockerd
,服务restart docker
等。 但是似乎没有什么可用的,因为我想我们不能在码头机内运行Docker。
我们可以有其他选择吗?
I want to build and test my app using dockerfile located in other private repository.
For that I'm using Alpine official docker image in which i run a bash script for cloning my private repo and running docker for building the docker image. This is how my.gitlab-ci.yml
looks like.
image: alpine:3.15
stages:
- main
main-job:
stage: main
script:
- apk add --update docker openrc
- rc-update add docker boot
- apk add bash git curl
- bash build.sh $GH_TOKEN $REPO
And I have simple script in build.sh
git clone https://${GH_TOKEN}@github.com/${REPO} source
cd source || exit 1
docker container prune --force || true
docker build . --rm --force-rm --compress --no-cache=true --pull --file Dockerfile -t test-app
docker image ls
docker run --privileged --rm -i test-app
But Docker don't start and spams error.
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
Also tried with other command in ubuntu docker like
service start docker
,dockerd
,service restart docker
and others.
But nothing seems to works as i guess we can't run docker inside a docker or something.
Can we have any alternative idea to it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来您没有运行Docker代理。您可以通过添加以下内容来使用Docker服务中的Docker:
有关更多信息,请参见构建Docker Images的Gitlab-Ci Docs: https://docs.gitlab.com/ee/ci/docker/using_docker_build.html
Looks like you don’t have a docker agent running. You can use the docker in docker service by adding the following:
See the GitLab-ci docs on building docker images for more info: https://docs.gitlab.com/ee/ci/docker/using_docker_build.html
我遇到了同样的问题。可能是您必须允许gitlab-runner在主机上。
I've meet the same issue. May be you have to permit gitlab-runner on your host.
我建议您构建并将构建的图像推到Dockerhub。然后,您可以启动引用预制图像的容器。
I‘d suggest you build and push your built image to dockerhub. Then you can start the container referencing your prebuilt image.