'docker: unauthorized: authentication required

I am trying to download and start a docker container like this:

docker run -it -p 8000:8000 -p 8060:8060 -h sandbox somegithubrepo bash

However, the downloading stops midway and I get this:

docker: unauthorized: authentication required.
See 'docker run --help'.

So I looked here: docker unauthorized: authentication required - upon push with successful login

I tried this:

docker push  mydockerhubusername/somerepo:latest

But I'm getting:

The push refers to a repository [docker.io/mydockerhubusername/somerepo]
An image does not exist locally with the tag: mydockerhubusername/somerepo

My ~/.docker/config.json looks like this:

{
        "auths": {
                "https://index.docker.io/v1/": {
                        "auth": "someKey"
                }
        }
}

So how can I download the container?



Solution 1:[1]

You don't download a container. You download an image, and then do a docker run on that image which then starts a container. For that to happen, the image has to exist somewhere - either in some Docker registry like the public DockerHub or your private registry or your local machine. If it doesn't exist on your local machine, docker run tries to docker pull it from DockerHub by default, or from the private registry if you're logged into one.

If you want to push the image from your local machine to a registry, you'll have to log into that registry on your machine, create a repository, build the image, and then docker push the image to that repository so that you can download it from somewhere else and start a container. Of course, to build an image, you'll need a Dockerfile, or some plugin in your project which builds it automatically for you.

Ex: Java image has already been published and I don't have it on my machine, so when I do docker run java, it starts to docker pull the image from the official DockerHub repository:

~ $: docker run java
Unable to find image 'java:latest' locally
latest: Pulling from library/java
386a066cd84a: Pull complete
...
...
...
Status: Downloaded newer image for java:latest

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1