Azure pipelines, Docker push to Nexus Repository Manager - docker

I have a repo with a simple docker file. I build it using the docker#2 task and would like to store the image on the nexus repository.
I created a service connection to the nexus repository manager as a Docker Registry and provided the credentials( URL : https://nexus.XX.de, name:DockerTest)
When I try to push it to the nexus repo, I fail. I get an error saying :
Starting: Push the image
==============================================================================
Task : Docker
Description : Build or push Docker images, login or logout, start or stop containers, or run a Docker command
Version : 2.214.0
Author : Microsoft Corporation
Help : https://aka.ms/azpipes-docker-tsg
==============================================================================
/usr/bin/docker images
/usr/bin/docker push nexus.XX.de/test:19899
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> bc4d269f1005 1 second ago 936MB
python 3.10 99199b67c562 12 hours ago 917MB
node 14 cc5014e36df3 5 days ago 916MB
node 16 5dd069ecb8d0 5 days ago 910MB
node 18 ee7f11c56c16 5 days ago 996MB
buildpack-deps buster cdc9ad60f652 5 days ago 803MB
buildpack-deps bullseye 732382fed651 5 days ago 835MB
debian 10 ff5db168d4c5 5 days ago 114MB
debian 11 20473158e8b3 5 days ago 124MB
node 18-alpine 708a2a137388 6 days ago 174MB
ubuntu 20.04 e40cf56b4be3 8 days ago 72.8MB
moby/buildkit latest fb2b14fffd09 13 days ago 168MB
ubuntu 18.04 5d2df19066ac 2 weeks ago 63.1MB
ubuntu 22.04 58db3edaf2be 2 weeks ago 77.8MB
node 14-alpine 399cc5685cda 4 weeks ago 123MB
node 16-alpine 0e1140518c5f 4 weeks ago 118MB
alpine 3.16 bfe296a52501 2 months ago 5.54MB
alpine 3.14 dd53f409bf0b 6 months ago 5.6MB
alpine 3.15 c4fc93816858 6 months ago 5.58MB
The push refers to repository [nexus.XX.de/test]
An image does not exist locally with the tag: nexus.XX.de/test
##[error]An image does not exist locally with the tag: nexus.XX.de/test
##[error]The process '/usr/bin/docker' failed with exit code 1
Finishing: Push the image
My Pipeline:
trigger:
none
resources:
- repo: self
variables:
tag: '$(Build.BuildId)'
stages:
- stage: Build
displayName: Build image
jobs:
- job: Build
displayName: Build
pool:
vmImage: ubuntu-latest
steps:
- task: Docker#2
displayName: logging in to the nexus repo
inputs:
containerRegistry: 'DockerTest'
command: 'login'
- task: Docker#2
displayName: Build an image
inputs:
command: build
dockerfile: '$(Build.SourcesDirectory)/Dockerfile'
tags: $(tag)
- task: Docker#2
displayName: Push the image
inputs:
containerRegistry: 'DockerTest'
repository: 'test'
command: 'push'
tags: |
$(tag)
Is it conceptually correct to expect this to happen? What are the things to consider?

You're not specifying a repository parameter for the Docker#2 build task, so the image isn't getting tagged. You can see this in the output you provided:
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> bc4d269f1005 1 second ago 936MB

Related

Docker tags are lost between steps in Bitbucket pipelines

I am using Bitbucket pipelines to build Docker images with Gradle. Here is my build:
definitions:
steps:
- step: &build-docker
name: Build Docker images
image:
name: openjdk:8
services:
- docker
script:
- ./gradlew dockerBuildImage
- docker image ls
caches:
- gradle-wrapper
- gradle
- docker
- step: &publish-docker
name: Publish Docker images
image:
name: docker
services:
- docker
script:
- docker image ls
caches:
- docker
pipelines:
default:
- step: *build-docker
- step: *publish-docker
My build.gradle.kts is configured to tag the images with UTC timestamps:
configure<DockerExtension> {
configure(this.getProperty("javaApplication"), closureOf<DockerJavaApplication> {
baseImage = "openjdk:8-jre-alpine"
tag = "${name}:${Instant.now().epochSecond}"
})
}
When I run dockerBuildImage task locally, I can see my tagged images:
$docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
…
forklift-1 1540454741 93fd78260bd1 5 weeks ago 105MB
forklift-2 1540454741 3c8e4e191fd3 5 weeks ago 105MB
forklift-3 1540454741 1e80caffd59e 5 weeks ago 105MB
forklift-4 1540454741 0e3d9c513144 5 weeks ago 105MB
…
The output from the "build-docker" step is like:
REPOSITORY TAG IMAGE ID CREATED SIZE
forklift-1 1543511971 13146b26fe19 1 second ago 105MB
forklift-2 1543511971 7581987997aa 3 seconds ago 105MB
forklift-3 1543511971 a6ef74a8530e 6 seconds ago 105MB
forklift-4 1543511970 a7087154d731 10 seconds ago 105MB
<none> <none> cfc622dd7b3c 3 hours ago 105MB
<none> <none> f17e20778baf 3 hours ago 105MB
<none> <none> 75cc06f4b5ee 3 hours ago 105MB
<none> <none> 1762b4f89680 3 hours ago 105MB
openjdk 8-jre-alpine 2e01f547f003 5 weeks ago 83MB
But the output of the second step does not have any tags, though the sizes of the images are roughly equivalent:
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> cfc622dd7b3c 3 hours ago 105MB
<none> <none> f17e20778baf 3 hours ago 105MB
<none> <none> 75cc06f4b5ee 3 hours ago 105MB
<none> <none> 1762b4f89680 3 hours ago 105MB
Where are the tags lost?
Note that some of the image IDs from the second step (docker image ls) seems to be same to those printed in the first step.
P.S. I know that if I need the tags (e.g. to publish) I can just do both build and publish in a single step.
While I was not able to track down the root cause, I made a simple workaround based on Docker's save and load commands and Bitbucket Pipelines' artifacts.
First, I've changed the tagging scheme a little bit:
configure<DockerExtension> {
configure(this.getProperty("javaApplication"), closureOf<DockerJavaApplication> {
baseImage = "openjdk:8-jre-alpine"
tag = "${name}:${System.getenv("DOCKER_TAG")}"
})
}
So instead of the UTC timestamp I rely on an environment variable DOCKER_TAG that I can set externally.
Then, define "build-docker" step as following:
- step: &build-docker
name: Build Docker images
image:
name: openjdk:8
services:
- docker
script:
- export DOCKER_TAG=${BITBUCKET_BUILD_NUMBER}
- ./gradlew dockerBuildImage
- docker save
--output images.tar
forklift-1:${DOCKER_TAG}
forklift-2:${DOCKER_TAG}
forklift-3:${DOCKER_TAG}
forklift-3:${DOCKER_TAG}
artifacts:
- images.tar
caches:
- gradle-wrapper
- gradle
I'm ok with using build numbers as tags, but any value can be provided.
Finally, the step that pushes the images is:
- step: &publish-docker
name: Publish Docker images
image:
name: docker
services:
- docker
script:
- docker load --input images.tar
- docker image ls
- docker push …
This works, because docker save
Produces a tarred repository to the standard output stream. Contains all parent layers, and all tags + versions, or specified repo:tag, for each argument provided.

Hyperledger Fabric: Can multiple docker images corresponding to different versions exist side by side?

I would like to know if one installs hyperledger fabric 1.2 by running
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh | bash -s 1.2.0
and then follows it up by running
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh | bash -s 1.3.0
then will the second command wipe out the docker images corresponding to v1.2? If not, then in docker-compose.yaml when some code like image: hyperledger/fabric-ca is encountered, how does docker know which version of hyperledger/fabric-ca to use?
From: https://hyperledger-fabric.readthedocs.io/en/release-1.3/install.html
The script does the following:
If needed, clone the hyperledger/fabric-samples repository
Checkout the appropriate version tag
Install the Hyperledger Fabric platform-specific binaries and config files for the version specified into the /bin and /config directories of fabric-samples
Download the Hyperledger Fabric docker images for the version specified
Passing 1.2.0 would download the corresponding docker images and additionally mark them as 'latest'.
Similarly, passing 1.3.0 would download the corresponding docker images and additionally mark them as 'latest'. Other images would not be deleted (from what I see in the script).
Now, when you specify image: hyperledger/fabric-ca in the docker-compose file, docker will automatically look for the latest tag (first locally, then in the registry).
Since the bootstrap script has been run for the required version, the corresponding image would be marked as latest, even if a newer version of that image is available locally - this would happen if you run 1.3.0 first, followed by 1.2.0 (1.2.0 would be tagged with latest)
The following is docker image ls after running 1.2.0, followed by 1.3.0 and then again 1.3.0
hyperledger/fabric-javaenv 1.3.0 2476cefaf833 6 weeks ago 1.7GB
hyperledger/fabric-javaenv latest 2476cefaf833 6 weeks ago 1.7GB
hyperledger/fabric-ca 1.3.0 5c6b20ba944f 6 weeks ago 244MB
hyperledger/fabric-ca latest 5c6b20ba944f 6 weeks ago 244MB
hyperledger/fabric-tools 1.3.0 c056cd9890e7 6 weeks ago 1.5GB
hyperledger/fabric-tools latest c056cd9890e7 6 weeks ago 1.5GB
hyperledger/fabric-ccenv 1.3.0 953124d80237 6 weeks ago 1.38GB
hyperledger/fabric-ccenv latest 953124d80237 6 weeks ago 1.38GB
hyperledger/fabric-orderer 1.3.0 f430f581b46b 6 weeks ago 145MB
hyperledger/fabric-orderer latest f430f581b46b 6 weeks ago 145MB
hyperledger/fabric-peer 1.3.0 f3ea63abddaa 6 weeks ago 151MB
hyperledger/fabric-peer latest f3ea63abddaa 6 weeks ago 151MB
hyperledger/fabric-zookeeper 0.4.13 e62e0af39193 7 weeks ago 1.39GB
hyperledger/fabric-zookeeper latest e62e0af39193 7 weeks ago 1.39GB
hyperledger/fabric-kafka 0.4.13 4121ea662c47 7 weeks ago 1.4GB
hyperledger/fabric-kafka latest 4121ea662c47 7 weeks ago 1.4GB
hyperledger/fabric-couchdb 0.4.13 1d3266e01e64 7 weeks ago 1.45GB
hyperledger/fabric-couchdb latest 1d3266e01e64 7 weeks ago 1.45GB
hyperledger/fabric-tools 1.2.0 379602873003 4 months ago 1.51GB
hyperledger/fabric-ccenv 1.2.0 6acf31e2d9a4 4 months ago 1.43GB
hyperledger/fabric-orderer 1.2.0 4baf7789a8ec 4 months ago 152MB
hyperledger/fabric-peer 1.2.0 82c262e65984 4 months ago 159MB

Docker-compose up -d:image not created

I am trying to create a basic web page with docker-compose
This is my yml file
identidock:
build: .
ports:
- "5000:5000"
environment:
ENV: DEV
volumes:
- ./app:/app
When I run
docker-compose up -d
it shows
Starting identidock_identidock_1 ... done
But if I check images
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
identidock_identidock latest b5003205377f 12 days ago 698MB
identidock latest 8eafce868d95 12 days ago 698MB
<none> <none> de77d0555129 13 days ago 698MB
<none> <none> 2f8bfc8f0a95 13 days ago 697MB
<none> <none> a42d37d82f28 2 weeks ago 535MB
<none> <none> 592d8c832533 2 weeks ago 695MB
python 3.4 41f9e544ec6c 2 weeks ago 684MB
It is obvious that new image has not been created.If I to http://localhost:5000/,
I got
Firefox can’t establish a connection to the server at localhost:5000.
This is docker ps -a output
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0414117eadd8 identidock_identidock "/cmd.sh" 12 days ago Exited (255) 11 days ago 9090/tcp, 0.0.0.0:5000->5000/tcp, 9191/tcp blissful_easley
4146fd976547 identidock_identidock:latest "/cmd.sh" 12 days ago Exited (255) 11 days ago 9090/tcp, 9191/tcp agitated_leakey
15d49655b290 identidock_identidock "/cmd.sh" 12 days ago Exited (1) 23 minutes ago identidock_identidock_1
And
docker-compose ps
Name Command State Ports
--------------------------------------------------
identidock_identidock_1 /cmd.sh Exit 1
Why?
The container may not have started. Check docker-compose ps. If the containers listed are not in Up state, then you can use docker-compose logs identidock to view the logs.

Push in docker private registry

I'm following https://docs.docker.com/registry/deploying/ and I have installed on docker.tp.cselt.it a private docker registry
> sudo docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry 2 65b0a3f42eef 7 days ago 165.8 MB
dockerui/dockerui latest 95c8b9dc91e0 6 weeks ago 6.13 MB
> sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e142b5f0933e registry:2 "/bin/registry /etc/ 7 minutes ago Up 7 minutes 0.0.0.0:5000->5000/tcp registry
1d5c9e515118 registry:2 "htpasswd -Bbn testu 7 minutes ago Exited (0) 7 minutes ago romantic_jang
ae7b5d62628f dockerui/dockerui:latest "/dockerui" About an hour ago Up About an hour 0.0.0.0:9000->9000/tcp goofy_meitner
On another machine, I'm trying to push an image (hello-world) on that registry:
> docker login docker.tp.cselt.it:5000
Username (testuser):
WARNING: login credentials saved in /home/administrator/.docker/config.json
Login Succeeded
> docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
b901d36b6f2f: Pull complete
0a6ba66e537a: Pull complete
Digest: sha256:8be990ef2aeb16dbcb9271ddfe2610fa6658d13f6dfb8bc72074cc1ca36966a7
Status: Downloaded newer image for hello-world:latest
> docker tag hello-world docker.tp.cselt.it:5000/hello-world
> docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
docker.tp.cselt.it:5000/hello-world latest 0a6ba66e537a 5 months ago 960 B
hello-world latest 0a6ba66e537a 5 months ago 960 B
> docker push docker.tp.cselt.it:5000/hello-world
The push refers to a repository [docker.tp.cselt.it:5000/hello-world] (len: 1)
0a6ba66e537a: Image already exists
b901d36b6f2f: Image already exists
latest: digest: sha256:1c7adb1ac65df0bebb40cd4a84533f787148b102684b74cb27a1982967008e4b size: 2744
Now, on the first machine (docker.tp.cselt.it):
> sudo docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry 2 65b0a3f42eef 7 days ago 165.8 MB
dockerui/dockerui latest 95c8b9dc91e0 6 weeks ago 6.13 MB
> sudo docker exec -it 65b0a3f42eef bash
> ls /var/lib/registry/docker/registry/v2/repositories/
centos hello-world ubuntu
But when I run:
> curl -u testuser:testpassword -X GET http://docker.tp.cselt.it:5000/v2/_catalog --noproxy docker.tp.cselt.it
I receive ""
What's wrong?
Riccardo
curl --noproxy docker.tp.cselt.it -u testuser:testpassword --insecure -X GET https://docker.tp.cselt.it:5000/v2/_catalog
{"repositories":["hello-world"]}

Docker not allowing push to repo

I'm following the Getting Started tutorial on the docker page, I have an image locally and have created a repo via the Docker Hub web page at https://hub.docker.com/r/banksysan/docker-whale/.
I've got a config.json like so:
{
"auths": {
"https://index.docker.io/v1/": {
"auth": "secret_string",
"email": "BanksySan#googlemail.com"
}
}
}
When I run the push though I get an authentication error:
David#Plod MINGW64 ~
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
banksysan/docker-whale latest 654156f34320 41 minutes ago 274.2 MB
docker-whale latest 654156f34320 41 minutes ago 274.2 MB
hello-world latest 0a6ba66e537a 3 months ago 960 B
kitematic/hello-world-nginx latest 38502dd72c08 7 months ago 7.913 MB
docker/whalesay latest ded5e192a685 8 months ago 247 MB
David#Plod MINGW64 ~
$ docker push banksysan/docker-whale
The push refers to a repository [docker.io/banksysan/docker-whale] (len: 1)
654156f34320: Preparing
unauthorized: access to the requested resource is not authorized
What extra thing do I need to do that I'm missing?

Resources