代码之家  ›  专栏  ›  技术社区  ›  Daniel Walker

Docker中的Docker:安装软件包

  •  0
  • Daniel Walker  · 技术社区  · 2 年前

    在我的GitLab CI管道中,我有一项工作,它使用pytest和docker compose的组合来测试我的代码(我的pytest fixture运行docker composite)。所以,我有这样的东西

    test job:
      image: ubuntu:20.04
      services:
        - docker:dind
      script:
        - apt -y update
        - apt -y install python3-pip docker-compose
        - ...
    

    然而,当我尝试运行各种Docker命令时,我得到

    无法连接到位于的Docker守护进程unix:///var/run/docker.sock.docker守护进程正在运行吗?

    我怎样才能连接到插座?当我从切换时 ubuntu:20.04 docker:latest ,它有效。然而,我无法访问任何Debian包。

    1 回复  |  直到 2 年前
        1
  •  2
  •   Daniel Walker    2 年前

    看见 https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#docker-in-docker-with-tls-enabled-in-the-docker-executor :

      # When you use the dind service, you must instruct Docker to talk with
      # the daemon started inside of the service. The daemon is available
      # with a network connection instead of the default
      # /var/run/docker.sock socket. Docker 19.03 does this automatically
      # by setting the DOCKER_HOST in
      # https://github.com/docker-library/docker/blob/d45051476babc297257df490d22cbd806f1b11e4/19.03/docker-entrypoint.sh#L23-L29
    

    其他容器不会自动设置它。设置 DOCKER_HOST 你自己

    variables:
      DOCKER_HOST: tcp://docker:2375
      DOCKER_TLS_CERTDIR: "/certs"