如何编写Dockerfile以运行另一个docker容器

如何编写Dockerfile以运行另一个docker容器,docker,dind,Docker,Dind,最近我们从gitlab shell executor迁移到了docker+machineexecutor 现在挑战来了,在我的.gitlab ci.yml中,我有两份工作,如下所示: stages: - RUN_TESTS build-docker: stage: RUN_TESTS script: - echo "Running the tests..." - apt-get update - docker build -t run-

最近我们从gitlab shell executor迁移到了
docker+machine
executor

现在挑战来了,在我的
.gitlab ci.yml
中,我有两份工作,如下所示:

stages:
  - RUN_TESTS

build-docker:
  stage: RUN_TESTS
  script:
    - echo "Running the tests..."
    - apt-get update 
    - docker build -t run-tests .
    - aws configure set aws_access_key_id ${effi_access_key}
    - aws configure set aws_secret_access_key ${effi_secrect_key}
    - aws configure set default.region ap-southeast-2
  only:
    - run-test
  tags:
    - shared-spot-runner

因此,我需要一个
docker
映像,它能够运行
apt get update
docker build-t运行测试。
和其他
aws
命令


问题是,如何编写具有所有这些依赖项的
Dockerfile
您可以对依赖项执行相同的操作,也可以基于docker映像中的docker创建新映像,并在gitlab ci中使用此映像

# This file is a template, and might need editing before it works on your project.
build-master:
  # Official docker image.
  image: my-repo/docker:dind-awscli
  stage: build
  services:
    - docker:dind
  script:
    - apk add nodejs
    - node app.js
    - docker ps
这使用了alpine,因此没有apt,您可以使用apk(alpine软件包管理器)。 您还可以将docker套接字装载到现有映像以及所有依赖项,以便将docker添加到映像中

编辑
从docker:dind创建docker图像

FROM docker:dind

RUN apk add --no-cache aws-cli
构建映像并将其推送到dockerhub或gitlab注册表:

docker build -t my-repo/docker:dind-awscli .
docker push my-repo/docker:dind-awscli
.gitlab ci.yml
中更改图像(如上面的示例中,我更新了它)

您可以在本地测试图像以确保其正常工作,并在需要时尝试添加更多应用程序:

docker run -it --rm my-repo/docker:dind-awscli sh
# Inside the container try
aws version

祝你好运

为什么你运行apt-get update而不安装任何东西?我也可以安装
aws
cli吗?使用
apk
?您好,它成功了,但现在我遇到了一个不同的错误,我打开了另一个问题,您能看一下吗?我刚才遇到了和你的另一个问题一样的错误,所以我回答了。