Richard Rublev
Richard Rublev

Reputation: 8164

Why am I not authorized? docker: you are not authorized to perform this operation: server returned 401

My Dockerfile

FROM openjdk:8-jdk-alpine

WORKDIR /opt/app

COPY target/pichk-0.0.1-SNAPSHOT.jar /opt/app/

CMD ["java","-jar","pichk-0.0.1-SNAPSHOT.jar"]
EXPOSE 8090

When I run image

docker run -p 8090:8090 pichk:001

I got error

docker: you are not authorized to perform this operation: server returned 401.

I am adding target permissions line

drwxrwxr-x   9 miki miki  4096 Jan  4 13:59 target/

docker inspect shows

"ContainerConfig": {
    "Hostname": "a85050e37362",
    "Domainname": "",
    "User": "",

What could cause this issue?

Upvotes: 1

Views: 2790

Answers (2)

Vijesh Nair
Vijesh Nair

Reputation: 31

Check whether the variable DOCKER_CONTENT_TRUST is enabled or not:

echo $DOCKER_CONTENT_TRUST

If the above shows 1, it means it is enabled and you should disable it by setting it to 0:

export $DOCKER_CONTENT_TRUST = 0

Your docker run command should work now.

Upvotes: 3

aameti
aameti

Reputation: 144

  1. Create a hub.docker.com account which comes with one free repository.

Then proceed with the steps below:

Here is my test Dockerfile:

FROM openjdk:8-jdk-alpine

WORKDIR /opt/app

COPY target/aamdevsecops-1.1.1-SNAPSHOT.jar /opt/app/

CMD ["java","-jar","aamdevsecops-1.1.1-SNAPSHOT.jar"]

Of course, i changed the <name>, <version> and <artifactoryId> in pom.xml file to match my Dockerfile.

First, i built the package locally by issuing this command on the intense-api git project folder:

mvn package

Then, I built the docker image out of it:

docker build -t aamdevsecops:1.1.1 .

then logged in to docker with my hub.docker.com credentials.

docker login # you will be prompted for credentials of hub.docker.com account

tagged the image: docker tag <Image ID> aamdevsecops/devops-bootcamp:latest

then: docker push aamdevsecops/devops-bootcamp:1.1.1

Finally, I did:

docker run --name aamdevsecops -p 8090:8090 aamdevsecops/devops-bootcamp:latest

And here's the result:

enter image description here

dissecting what terms mean:

docker tag <image id> aamdevsecops/devops-bootcamp:latest
  • tags the image id locally created with docker build -t command, adds a tag to it. (a version).
docker push aamdevsecops/devops-bootcamp
  • pushes the image into hub.docker.com

docker run --name aamdevsecops -p 8090:8090 aamdevsecops/devops-bootcamp:latest

  • runs the container from the remote repository created on hub.docker.com

Upvotes: 1

Related Questions