Skip to content

Commit 1641c9e

Browse files
committed
check the docker login checks
1 parent 3f86913 commit 1641c9e

1 file changed

Lines changed: 31 additions & 10 deletions

File tree

verify.sh

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,31 @@ if ! docker pull alpine:latest; then
8484
exit 1
8585
fi
8686

87-
# Tag and push the image to the local registry with error handling
88-
echo "Tagging and pushing the alpine:latest image to the local registry..."
89-
if ! docker tag alpine:latest localhost:5000/alpine; then
90-
echo "Error: Failed to tag the alpine:latest image." >&2
91-
exit 1
92-
fi
87+
# Use echo with --password-stdin for secure login
88+
echo "password" | docker login localhost:5000 -u user --password-stdin
9389

90+
# Tag and push the image to the local registry
91+
docker tag alpine:latest localhost:5000/alpine
9492
if ! docker push localhost:5000/alpine; then
9593
echo "Error: Failed to push the alpine:latest image to the local registry." >&2
94+
docker logs registry >&2
95+
exit 1
96+
fi
97+
98+
# Debugging: Check if the registry is running
99+
if ! docker ps | grep -q registry; then
100+
echo "Error: Registry container is not running." >&2
101+
docker logs registry >&2
102+
exit 1
103+
fi
104+
105+
# Debugging: Check registry logs before pushing
106+
echo "Checking registry logs before pushing the image..."
107+
docker logs registry
108+
109+
# Debugging: Verify registry accessibility
110+
if ! curl -s -u user:password -X GET http://localhost:5000/v2/ > /dev/null; then
111+
echo "Error: Unable to access the registry at localhost:5000." >&2
96112
exit 1
97113
fi
98114

@@ -101,16 +117,21 @@ echo "Verifying the image in the local registry..."
101117
catalog=$(curl -s -u user:password -X GET http://localhost:5000/v2/_catalog)
102118
echo "Registry catalog: $catalog"
103119

104-
# Step 4: Use basic-docker to pull and run the image from the local registry
105-
echo "Using basic-docker to pull and run the image from the local registry..."
120+
# Step 4: Use basic-docker to pull the image from the local registry
121+
if ! ./basic-docker pull user:password@localhost:5000/alpine; then
122+
echo "Error: basic-docker failed to pull the image from the local registry." >&2
123+
exit 1
124+
fi
125+
126+
# Step 5: Use basic-docker to run the image
106127
if ./basic-docker run user:password@localhost:5000/alpine /bin/sh -c "echo Hello from authenticated local registry"; then
107128
echo "basic-docker successfully pulled and ran the image."
108129
else
109-
echo "Error: basic-docker failed to pull or run the image." >&2
130+
echo "Error: basic-docker failed to run the image." >&2
110131
exit 1
111132
fi
112133

113-
# Step 5: Check logs for authentication
134+
# Step 6: Check logs for authentication
114135
echo "Checking logs for authentication..."
115136
docker logs registry | grep "user"
116137

0 commit comments

Comments
 (0)