代码之家  ›  专栏  ›  技术社区  ›  K.Os

尝试在TeamCity中构建和运行Docker容器时出错

  •  0
  • K.Os  · 技术社区  · 4 年前

    我想构建我的Android Dockerfile,在这个构建步骤之后运行另一个步骤。

    构建Docker映像的步骤很简单: enter image description here

    所以命令很简单:

    docker build -t android-build:android-template -f Dockerfile .
    

    我的文档如下:

    FROM openjdk:11.0.7
    
    ENV SDK_URL="https://dl.google.com/android/repository/commandlinetools-linux-6604631_latest.zip" \
        ANDROID_HOME="/usr/local/android-sdk" \
        ANDROID_VERSION=29 \
        ANDROID_BUILD_TOOLS_VERSION=28.0.3 \
    
    RUN mkdir "$ANDROID_HOME" .android \
        && cd "$ANDROID_HOME" \
        && curl -o sdk.zip $SDK_URL \
        && unzip sdk.zip \
        && rm sdk.zip
    
    RUN yes | $ANDROID_HOME/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME --licenses
    
    RUN $ANDROID_HOME/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME --update
    
    RUN yes | $ANDROID_HOME/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME \
        "build-tools;${ANDROID_BUILD_TOOLS_VERSION}" \
        "platforms;android-${ANDROID_VERSION}"
    
    RUN mkdir /application
    
    WORKDIR /application
    

    enter image description here

    整个错误日志如下:

     time="2020-07-18T22:01:27Z" level=error msg="failed to dial gRPC: cannot connect to the Docker daemon. Is 'docker daemon' running on this host?: dial unix /var/run/docker.sock: connect: no such file or directory"
    00:01:27
      time="2020-07-18T22:01:27Z" level=error msg="Can't add file /opt/buildagent/work/da45177e2c517d09/.git/index to tar: io: read/write on closed pipe"
    00:01:27
      time="2020-07-18T22:01:27Z" level=error msg="Can't close tar writer: io: read/write on closed pipe"
    00:01:27
      error during connect: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.40/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&session=fvz9t2pm9dkmopc06bf6yxqa5&shmsize=0&t=android-build%3Aandroid-template&target=&ulimits=null&version=1: context canceled
    00:01:27
      Process exited with code 1
    00:01:28
      Process exited with code 1 (Step: Build a Docker container (Command Line))
    00:01:28
      Step Build a Docker container (Command Line) failed
    

    我正在运行docker compose文件:

    version: "3.1"
    services:
      tcs:
        image: jetbrains/teamcity-server
        container_name: teamcity-server
        ports:
          - "8111:8111"
        volumes:
          - teamcity/server/data:/data/teamcity_server/datadir
          - teamcity/server/logs:/opt/teamcity/logs
      tca:
        image: jetbrains/teamcity-agent
        depends_on:
          - tcs
        container_name: teamcity-agent
        environment:
          - DOCKER_IN_DOCKER=start
          - SERVER_URL=http://tcs:8111/
        privileged: true
        volumes:
          - /teamcity/agent:/data/teamcity_agent/conf
    

    Mac上:macOS Catalina版本10.15.5

    0 回复  |  直到 4 年前
        1
  •  0
  •   Brian Pursley    4 年前

    这里发生了几件事。

    首先,我认为你需要安装主机 /var/run/docker.sock 你的构建代理。

    在命令行中,它如下所示:

    docker run -e DOCKER_IN_DOCKER=start --privileged -v /var/run/docker.sock:/var/run/docker.sock -it jetbrains/teamcity-agent:2019.2.4 /bin/bash
    

    所以在docker compose中,我猜你需要这样的东西:

      volumes:
         - /var/run/docker.sock:/var/run/docker.sock
    

    第二,经济形势发生了变化 version 2020.1 它不再作为根运行。

    因此,如果使用2020版或更高版本的构建代理,则可能需要在docker compose中指定根用户,以便docker中的docker正常工作。所以在docker作曲中我想你会加上 user: root 在图像线下。