Uploaded image for project: 'Bitbucket Cloud'
  1. Bitbucket Cloud
  2. BCLOUD-17319

Docker builds started failing with "Container ID cannot be mapped to a host ID" error

    XMLWordPrintable

Details

    Description

      Recently, our builds have started failing with the message:

      Error processing tar file(exit status 1): Container ID 165586 cannot be mapped to a host ID
      

      I can't figure out which part is failing, though from browsing other issues it appears to be some issue with user remapping. However, the only existing issues I can find that sound similar are to do with multistage builds. The build is failing some time after the apt-get autoremove in the following:

      # Copy requirements in
      COPY ./requirements.txt /app/
      COPY requirements/ /app/requirements/
      
      WORKDIR /app
      # Install dependencies and requirements
      
      RUN apt-get update && apt-get install -y pkg-config git build-essential python-dev \
      && pip install --upgrade pip \
      && pip install --upgrade setuptools \
      && pip install -r requirements/server.txt \
      && rm -rf requirements/dependencies \
      && apt-get remove -y build-essential git pkg-config \
      && apt-get autoremove -y \
      && rm -rf /var/lib/apt/lists/*
      
      # Copy the rest of the app
      COPY . /app/
      
      # Custom system config
      COPY server/ /
      

       


       Additional Information

      Identifying the right owner of the file/folders being exchanged between Docker containers that result in the error "Container ID cannot be mapped to a host ID" during a pipeline run?

       This is important in resolving related issues, as once the file(s)/folder(s) are identified. Their ownership can be changed to 'root' in order to avoid the resulting error.

      Example error: "Container ID 165569 cannot be mapped to a host ID" we can make an initial conclusion that the container ID 165569 is unable to map with the host ID. It is important to get the right user ID on the host container from the child container ID 165569 pointing to. Steps below help to find the same:


      Docker user namespace configurations are stored within the following two files '/etc/subuid' and '/etc/subgid', which looks as follows on Bitbucket Pipelines:

      pipelines:100000:65536
      

      For instance, with "pipelines:100000:65536" it means that user pipelines can use 65536 user ids starting at 100000. Now a user ID 165569 on a host container would refer to 165569 - (100000+65536) = 33

      After getting the host user ID, you can use the following command to find all the files that belong to it:

      RUN find / -uid 33 -ls
      

      Ideally, for a multi-stage build and DinD setup, the easiest trick to make everything working is by changing the ownership of the folder to root that is failing to get copied to the child container:

      chown -R root:root file/folder

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              951f67ec5362 Alastair McFarlane
              Votes:
              57 Vote for this issue
              Watchers:
              52 Start watching this issue

              Dates

                Created:
                Updated: