Docker Push Fails: "Layer already exists"

I have the following script to push my image using Travis CI build pipeline:

#!/usr/bin/env bash
if [ $TRAVIS_BRANCH == “master” ]; then
echo “$DOCKER_PASSWORD” | docker login -u “$DOCKER_REGISTRY_USERNAME” --password-stdin;
docker build -t $DOCKER_APP_NAME .;
docker images;
docker tag $DOCKER_APP_NAME $DOCKER_REGISTRY_USERNAME/$DOCKER_APP_NAME;
echo “Pushing image $DOCKER_APP_NAME to repository $DOCKER_REGISTRY_URL”;
docker push $DOCKER_TAG_NAME;
docker push $DOCKER_REGISTRY_USERNAME/$DOCKER_APP_NAME;
fi

When I execute the build pipeline, I get to see the following error:

Successfully tagged [secure]
REPOSITORY TAG IMAGE ID CREATED SIZE
Docker 1.0-SNAPAHOT e74c33326bb3 Less than a second ago 227MB
anapsix/alpine-java jdk8 ed55c27d366d 3 years ago 171MB
Pushing image [secure] to repository hub.docker.com
The push refers to repository [docker.io/[secure]/plant-simulator]
An image does not exist locally with the tag: [secure]/plant-simulator
The push refers to repository [docker.io/[secure]/hub.docker.com/[secure]/plant-simulator]
8c08446ff254: Preparing
aaecc90e7c56: Preparing
02bf7502d0a8: Preparing
d5ead368c960: Preparing
4fe15f8d0ae6: Preparing
denied: requested access to the resource is denied
The command “bash docker_push.sh” exited with 1.

I checked my repo in docker hub and it is indeed set to public, but nevertheless I get this error. I also see something like this printed in the travis ci build logs:

19.33s$ bash docker_push.sh

720Error: Cannot perform an interactive login from a non TTY device

721Sending build context to Docker daemon 352.1MB

722Step 1/15 : FROM anapsix/alpine-java:jdk8

723jdk8: Pulling from anapsix/alpine-java

Why do I get the interactive login error? Could this be the reason?

Hey @joesan,

For a test have you tried running the following?

docker login -u "username" -p "password" docker.io && docker push personalhub/reponame:latest

Was wondering if you could push via Docker this way, if you can it gives me some ideas, but let’s see first. Thank you for your patience.

-Montana (Travis CI Staff)

It still did not solve the issue wven after adding that docker.io to the end of the login command. Hast it got something to do with sudo? My docker commands are running as a shell script!

I tried the command locally on my machine and it works both with and without the docker.io at the end of the login command!

I can confirm that this looks like a bug in Travis CI that it is unable to push this project into Docker hub. I was able to build tag and push the image from my local machine without any issues! Here is the project that I have been working on:

What happened here?
https://travis-ci.org/joesan/plant-simulator/jobs/656187400

1 Like

Ok I managed to fix it now! It was some script error!