我正在开发一个基于 spring-boot 的项目,并使用 本地计算机作为测试环境将其部署为 docker 容器。
我正在创建一个 bitbucket 管道,它可以自动执行构建和部署之间的所有操作。对于这个管道,我使用了一个自托管运行器(docker),它也在我计划部署项目的同一台机器和docker实例上运行。
我成功构建了项目(mvn 和 docker),并将 docker 镜像加载到我的 GCP 容器注册表中。
我的最终部署步骤(docker run xxx,请参阅下面的 yml 脚本)也成功,但由于它在容器本身中运行,因此它没有在顶级 docker 上运行脚本。 据我了解,跑步者本身可以访问主机 docker,因为 docker.sock 已安装。但每一步都会创建另一个容器,该容器无法访问 docker.sock,对吗?所以基本上我需要知道如何授予对该文件的访问权限,除非有更好的解决方案。
这里是缩短的管道定义:
image: maven:3.8.7-openjdk-18
definitions:
services:
docker:
image: docker:dind
pipelines:
default:
# build only for feature branches or so
branches:
test:
# build, docker and upload steps
- step:
name: Deploy
deployment: test
image: google/cloud-sdk:alpine
runs-on:
- 'self.hosted'
- 'linux'
caches:
- docker
script:
- IMAGE_NAME=$BITBUCKET_REPO_SLUG
- VERSION="${BITBUCKET_BUILD_NUMBER}"
- DOCKER_IMAGE="${DOCKER_REGISTRY}/${IMAGE_NAME}:${VERSION}"
# Authenticating with the service account key file
- echo $GCLOUD_API_KEYFILE > ./gcloud-api-key.json
- gcloud auth activate-service-account --key-file gcloud-api-key.json
- gcloud config set project $GCLOUD_PROJECT
# Login with docker and stop old container (if exists) and run new one
- cat ./gcloud-api-key.json | docker login -u _json_key --password-stdin https://eu.gcr.io
- docker ps -q --filter "name=${IMAGE_NAME}" | xargs -r docker stop
- docker run -d -p 82:8080 -p 5005:5005 --name ${IMAGE_NAME} --rm ${DOCKER_IMAGE}
services:
- docker
你好,我也遇到了同样的问题,你有办法解决吗?
我现在正在 docker 容器内运行 bitbucket runnerShell,并且该 docker 容器可以访问 docker.sock