.net 免费在线gitlab runner上的docker中的docker
我有一个dotnet解决方案,它由控制台项目、webapi项目和mysql数据库组成。我把它们放在单独的docker图像中,编写docker compose启动并在我的机器上测试。接下来,我使用FluentDocker编写了一个测试,它允许我以编程方式启动docker compose,并验证容器是否已启动和运行 现在我想在Gitlab CI上做这个。以前我使用image:mcr.microsoft.com/dotnet/core/sdk:3.1,并对测试项目运行测试阶段。它工作得很好,因为没有docker集成。我无法在Gitlab CI上运行FluentDocker测试,因为映像不包含docker。于是我开始研究.net 免费在线gitlab runner上的docker中的docker,.net,docker,gitlab,.net,Docker,Gitlab,我有一个dotnet解决方案,它由控制台项目、webapi项目和mysql数据库组成。我把它们放在单独的docker图像中,编写docker compose启动并在我的机器上测试。接下来,我使用FluentDocker编写了一个测试,它允许我以编程方式启动docker compose,并验证容器是否已启动和运行 现在我想在Gitlab CI上做这个。以前我使用image:mcr.microsoft.com/dotnet/core/sdk:3.1,并对测试项目运行测试阶段。它工作得很好,因为没有d
4-dind示例我们公司也有同样的情况,但有一个自托管docker/gitlab等 目前,我们正在gitlab runner(您的第2个)中运行docker集成,并产生了一系列不良副作用,例如:gitlab runner创建的容器没有正确清理,因为gitlab runner没有考虑清理,因为在正常情况下,docker runner本身应该关闭(wihtout)毁灭一切
选项3不是一件坏事,它是一个默认的和完全正常的事情:我们有一堆docker图像,其中包括加载的图像中没有提供的库。你会习惯的,所以我更喜欢这样。是一个干净的解决方案,它不会让人感觉到“黑客”的味道。在GitLab CI中使用docker的标准方法如GitLab examples repo所示。我假设它与free runner一起工作,因为它是GitLab自己维护的官方组 由于您的工作需要的不仅仅是Docker,我建议您在Dotnet SDK、Docker和Docker compose中使用自定义映像,如下所示:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine
RUN apk add --no-cache \
ca-certificates \
# DOCKER_HOST=ssh://... -- https://github.com/docker/cli/pull/1014
openssh-client
# set up nsswitch.conf for Go's "netgo" implementation (which Docker explicitly uses)
# - https://github.com/docker/docker-ce/blob/v17.09.0-ce/components/engine/hack/make.sh#L149
# - https://github.com/golang/go/blob/go1.9.1/src/net/conf.go#L194-L275
# - docker run --rm debian:stretch grep '^hosts:' /etc/nsswitch.conf
RUN [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf
ENV DOCKER_CHANNEL stable
ENV DOCKER_VERSION 19.03.12
# TODO ENV DOCKER_SHA256
# https://github.com/docker/docker-ce/blob/5b073ee2cf564edee5adca05eee574142f7627bb/components/packaging/static/hash_files !!
# (no SHA file artifacts on download.docker.com yet as of 2017-06-07 though)
RUN set -eux; \
\
# this "case" statement is generated via "update.sh"
apkArch="$(apk --print-arch)"; \
case "$apkArch" in \
# amd64
x86_64) dockerArch='x86_64' ;; \
# arm32v6
armhf) dockerArch='armel' ;; \
# arm32v7
armv7) dockerArch='armhf' ;; \
# arm64v8
aarch64) dockerArch='aarch64' ;; \
*) echo >&2 "error: unsupported architecture ($apkArch)"; exit 1 ;;\
esac; \
\
if ! wget -O docker.tgz "https://download.docker.com/linux/static/${DOCKER_CHANNEL}/${dockerArch}/docker-${DOCKER_VERSION}.tgz"; then \
echo >&2 "error: failed to download 'docker-${DOCKER_VERSION}' from '${DOCKER_CHANNEL}' for '${dockerArch}'"; \
exit 1; \
fi; \
\
tar --extract \
--file docker.tgz \
--strip-components 1 \
--directory /usr/local/bin/ \
; \
rm docker.tgz; \
\
dockerd --version; \
docker --version
COPY modprobe.sh /usr/local/bin/modprobe
COPY docker-entrypoint.sh /usr/local/bin/
# https://github.com/docker-library/docker/pull/166
# dockerd-entrypoint.sh uses DOCKER_TLS_CERTDIR for auto-generating TLS certificates
# docker-entrypoint.sh uses DOCKER_TLS_CERTDIR for auto-setting DOCKER_TLS_VERIFY and DOCKER_CERT_PATH
# (For this to work, at least the "client" subdirectory of this path needs to be shared between the client and server containers via a volume, "docker cp", or other means of data sharing.)
ENV DOCKER_TLS_CERTDIR=/certs
# also, ensure the directory pre-exists and has wide enough permissions for "dockerd-entrypoint.sh" to create subdirectories, even when run in "rootless" mode
RUN mkdir /certs /certs/client && chmod 1777 /certs /certs/client
# (doing both /certs and /certs/client so that if Docker does a "copy-up" into a volume defined on /certs/client, it will "do the right thing" by default in a way that still works for rootless users)
ENV COMPOSE_VERSION 1.26.2
RUN apk add --no-cache py3-pip python3
RUN apk add --no-cache --virtual build-dependencies python3-dev libffi-dev openssl-dev gcc libc-dev make \
&& pip3 install "docker-compose${COMPOSE_VERSION:+==}${COMPOSE_VERSION}" \
&& apk del build-dependencies
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["sh"]
这是基于官方的docker:latest
以及tmaier/docker compose:latest
。您还需要来自第一次回购的modprobe.sh
和docker entrypoint.sh
脚本
然后按如下方式运行它:
image: docker:latest //whatever image you use in your pipeline most often
variables:
DOCKER_DRIVER: overlay2
stages:
- test
test:
stage: test
image: dotnetsdk-compose:latest //your custom image
services:
- docker:dind
script:
- docker-compose up -d
请注意,新图像基于Alpine 3.12而不是Debian 10。如果这是一个问题,您必须将上面的Dockerfile转换为使用Debian上可用的命令。我尝试使用#3实现,但失败了,在docker中的规范docker解释中,这是一个强烈的否定:)另一个答案描述了如何做到这一点,所以我现在会研究一下,如果你记得用LF行结尾保存,*.sh文件的内容,复制粘贴效果很好。你能接受我的回答吗?