How can I solve getting Unauthorized Access 401 error when pulling aws deep learning container with docker?

Viewed 5029

I tried building a detectron2 image with docker, in order to use with AWS SageMaker. The dockerfile looks like this:

ARG REGION="eu-central-1"

FROM 763104351884.dkr.ecr.$REGION.amazonaws.com/pytorch-training:1.6.0-gpu-py36-cu101-ubuntu16.04

RUN pip install --upgrade torch==1.6.0+cu101 torchvision==0.7.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html

############# Detectron2 section ##############
RUN pip install \
    --no-cache-dir pycocotools~=2.0.0 \
    --no-cache-dir https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/torch1.6/detectron2-0.4%2Bcu101-cp36-cp36m-linux_x86_64.whl

   
ENV FORCE_CUDA="1"
# Build D2 only for Volta architecture - V100 chips (ml.p3 AWS instances)
# ENV TORCH_CUDA_ARCH_LIST="Volta"

# Set a fixed model cache directory. Detectron2 requirement
ENV FVCORE_CACHE="/tmp"

############# SageMaker section ##############

COPY container_training/sku-110k /opt/ml/code
WORKDIR /opt/ml/code

ENV SAGEMAKER_SUBMIT_DIRECTORY /opt/ml/code
ENV SAGEMAKER_PROGRAM training.py

WORKDIR /

ENTRYPOINT ["bash", "-m", "start_with_right_hostname.sh"]

The problem is that when I run the docker build command, it fails at pulling the image from the AWS ECR repository. It throws the error

ERROR [internal] load metadata for 763104351884.dkr.ecr.eu-central-1.amazonaws.com/pytorch-training:1.6.0-gpu 0.4s ------ > [internal] load metadata for 763104351884.dkr.ecr.eu-central-1.amazonaws.com/pytorch-training:1.6.0-gpu-py36-cu101-ubuntu16.04: ------ failed to solve with frontend dockerfile.v0: failed to create LLB definition: unexpected status code [manifests 1.6.0-gpu-py36-cu101-ubuntu16.04]: 401 Unauthorized

I have to mention that I successfully login before trying to build and I have full ECR permissions on my user.

1 Answers

you probably logged in in your ECR private account but not in docker & shared ECR repo to retrieve Pytorch base image like this :

Enter your region and account id below, and then execute the following cell to do it.

%%bash

REGION=YOUR_REGION
ACCOUNT=YOUR_ACCOUNT_ID

aws ecr get-login-password --region $REGION | docker login --username AWS --password-stdin 763104351884.dkr.ecr.$REGION.amazonaws.com

# loging to your private ECR
aws ecr get-login-password --region $REGION | docker login --username AWS --password-stdin $ACCOUNT.dkr.ecr.$REGION.amazonaws.com
Related