我将通过https://docs.docker.com/registry/deploying/来设置一个本地注册表。
docker run -d -p 5000:5000 --restart=always --name reg ubuntu:16.04
当我尝试运行以下命令时:
$ docker push localhost:5000/my-ubuntu
我得到了错误:
Get http://localhost:5000/v2/: dial tcp 127.0.0.1:5000: connect:connection refused
有什么想法吗?
发布于 2018-10-08 17:22:34
连接被拒绝通常意味着您试图连接的服务实际上没有正常启动和运行。可能还有this问题中概述的其他原因,但本质上,对于您的情况,这只是意味着注册表还没有打开。
在执行任何其他操作之前,请等待注册表容器正确创建-从official docker image创建本地注册表的docker run -d -p 5000:5000 --restart=always --name registry registry:2
。
通过运行docker ps | grep registry
确保registry
容器已启动,然后继续下一步。
发布于 2021-01-06 10:05:21
更多关于
如果您正在使用Minikube,并且想要从127.0.0.1:5000中拉下一个镜像,
然后你会遇到下面的错误:
拉取镜像“127.0.0.1:5000/nginx_operator:latest”失败: rpc错误:代码=未知描述=来自守护进程的错误响应:获取http://127.0.0.1:5000/v2/:拨号tcp 127.0.0.1:5000: connect:连接被拒绝
完整日志:
$ kubectl describe pod/your_pod
...
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 2m29s default-scheduler Successfully assigned tj-blue-whale-05-system/tj-blue-whale-05-controller-manager-6c8f564575-kwxdv to minikube
Normal Pulled 2m25s kubelet Container image "gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0" already present on machine
Normal Created 2m24s kubelet Created container kube-rbac-proxy
Normal Started 2m23s kubelet Started container kube-rbac-proxy
Normal BackOff 62s (x5 over 2m22s) kubelet Back-off pulling image "127.0.0.1:5000/nginx_operator:latest"
Warning Failed 62s (x5 over 2m22s) kubelet Error: ImagePullBackOff
Normal Pulling 48s (x4 over 2m23s) kubelet Pulling image "127.0.0.1:5000/nginx_operator:latest"
Warning Failed 48s (x4 over 2m23s) kubelet Failed to pull image "127.0.0.1:5000/nginx_operator:latest": rpc error: code = Unknown desc = Error response from daemon: Get http://127.0.0.1:5000/v2/: dial tcp 127.0.0.1:5000: connect: connection refused
Warning Failed 48s (x4 over 2m23s) kubelet Error: ErrImagePull
可能的根本原因:
注册表必须设置在Minikube端,而不是您的主机端。
即
注册表主机:注册表(127.0.0.1:5000)
如何检查?
Step1:检查您的Minikube容器
$ docker ps -a
CONTAINER ID IMAGE ... STATUS PORTS NAMES
8c6f49491dd6 gcr.io/k8s-minikube/kicbase:v0.0.15-snapshot4 ... Up 15 hours 127.0.0.1:49156->22/tcp, 127.0.0.1:49155->2376/tcp, 127.0.0.1:49154->5000/tcp, 127.0.0.1:49153->8443/tcp minikube
# your Minikube is under running
# host:49154 <--> minikube:5000
# where:
# - port 49154 was allocated randomly by the docker service
# - port 22: for ssh
# - port 2376: for docker service
# - port 5000: for registry (image repository)
# - port 8443: for Kubernetes
Step2:登录到您的Minikube
$ minikube ssh
docker@minikube:~$ curl 127.0.0.1:5000
curl: (7) Failed to connect to 127.0.0.1 port 5000: Connection refused
# setup
# =====
# You did not setup the registry.
# Let's try to setup it.
docker@minikube:~$ docker run --restart=always -d -p 5000:5000 --name registry registry:2
# test
# ====
# test the registry using the following commands
docker@minikube:~$ curl 127.0.0.1:5000
docker@minikube:~$ curl 127.0.0.1:5000/v2
<a href="/v2/">Moved Permanently</a>.
docker@minikube:~$ curl 127.0.0.1:5000/v2/_catalog
{"repositories":[]}
# it's successful
docker@minikube:~$ exit
logout
Step3:构建您的镜像,并将其推送到您的Minikube的注册表中
# Let's take nginx as an example. (You can build your own image)
$ docker pull nginx
# modify the repository (the source and the name)
$ docker tag nginx 127.0.0.1:49154/nginx_operator
# check the new repository (source and the name)
$ docker images | grep nginx
REPOSITORY TAG IMAGE ID CREATED SIZE
127.0.0.1:49154/nginx_operator latest ae2feff98a0c 3 weeks ago 133MB
# push the image into the registry of your Minikube
$ docker push 127.0.0.1:49154/nginx_operator
Step4:再次登录您的Minikube
$ minikube ssh
# check the registry
$ curl 127.0.0.1:5000/v2/_catalog
{"repositories":["nginx_operator"]}
# it's successful
# get the image info
$ curl 127.0.0.1:5000/v2/nginx_operator/manifests/latest
docker@minikube:~$ exit
logout
自定义Minikube的暴露端口
如果您想在主机端使用端口5000,而不是使用49154 (由docker服务随机分配)
即主机:5000 <--> minikube:5000
您需要重新创建一个带有--ports
标志的minikube实例
# delete the old minikube instance
$ minkube delete
# create a new one (with the docker driver)
$ minikube start --ports=5000:5000 --driver=docker
# or
$ minikube start --ports=127.0.0.1:5000:5000 --driver=docker
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5d1e5b61a3bf gcr.io/k8s-minikube/kicbase:v0.0.15-snapshot4 "/usr/local/bin/entr…" About a minute ago Up About a minute 0.0.0.0:5000->5000/tcp, 127.0.0.1:49162->22/tcp, 127.0.0.1:49161->2376/tcp, 127.0.0.1:49160->5000/tcp, 127.0.0.1:49159->8443/tcp minikube
$ docker port minikube
22/tcp -> 127.0.0.1:49162
2376/tcp -> 127.0.0.1:49161
5000/tcp -> 127.0.0.1:49160
5000/tcp -> 0.0.0.0:5000
8443/tcp -> 127.0.0.1:49159
你可以看到:0.0.0.0:5000->5000/tcp
在Minikube中重新测试注册表
# in the host side
$ docker pull nginx
$ docker tag nginx 127.0.0.1:5000/nginx_operator
$ docker ps -a
$ docker push 127.0.0.1:5000/nginx_operator
$ minikube ssh
docker@minikube:~$ curl 127.0.0.1:5000/v2/_catalog
{"repositories":["nginx_operator"]}
# Great!
https://stackoverflow.com/questions/52698748
复制相似问题