docker push to registry does not work - docker

I am facing issues when I try to push to registry that I created earlier. Here are the steps that I followed.
docker run -d -p 5001:5002 --restart=always --name new_registry registry:2
docker build -t test-app .
docker run -p 50100:8080 -d --name app test-app
docker tag test-app localhost:5001/test:latest
docker push localhost:5001/test:latest
=================================================
✘  ~/G/S/d/a/App   master  docker push localhost:5001/test:latest
The push refers to a repository [localhost:5001/test] (len: 1)
Sending image list
Put http://localhost:5001/v1/repositories/test/: net/http: transport closed before response was received
Below is output of docker images command:
 ~/G/S/d/a/App   master  docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
test-app latest 78f9362f7cd5 51 minutes ago 547.8 MB
localhost:5001/test latest 78f9362f7cd5 51 minutes ago 547.8 MB
registry 2 5d165b8e4b20 3 weeks ago 220.1 MB
More Details Below:
~/G/S/d/a/patterns_and_tools  docker-machine env default
set -x DOCKER_TLS_VERIFY "1";
set -x DOCKER_HOST "tcp://192.168.yyy.xxx:2376";
set -x DOCKER_CERT_PATH "/Users/zack/.docker/machine/machines/default";
set -x DOCKER_MACHINE_NAME "default";
# Run this command to configure your shell:
# eval (docker-machine env default)
~/G/S/d/a/patterns_and_tools 
I checked the network settings in the VM . They are as below:
Name : dockersetting
protocol : TCP
HOST IP:
HOST PORT : 50100
GuestIP :
Guest Port : 50100

A tag boot2docker (even though it has been obsoleted by docker machine) means you are not on Linux directly, but on Windows or Mac, using a Linux VM.
You have a similar error message reported in issue 523 of docker/distribution (the new registry server)
When you bind to localhost inside the container, the service won't be available outside the container, even though you are specifying the port mapping.
When the docker daemon goes to connect, it cannot connect to the port since the service is not bound to the "external" interface of the container.
That means you need to setup port forwarding, or to use the docker-machine ip new_registry ip address.
docker push $(docker-machine ip new_registry):5001/test:latest
5000:5000 works but 5001:5002 does not work when creating registry.
It is possible that the VM was already set to port forward port 5000, but not 5001 (similar to this picture).
It means the registry image exposes port 5000: you can map that on host port 5000 or 5001 or any port you want: but it has to be port 5000 that you map:
docker run -d -p 5001:5000 --restart=always --name new_registry registry:2
^^^^

Related

Cannot connect to docker container webapp from different system

If I run my docker container as
docker run -ti --privileged=true -p 5010:5000 myapp
I cannot connect to myapp by https://:5010
But if I run my docker container as
docker run -ti --privileged=true -p 5000:5000 myapp
I can connect to myapp by https://:5000 from different machine
What can be the issue? What option should I use to map container port to host port with different number?
output of nestat
Interestingly I can connect to my web server from same machine by wget command
This is the output of the netstat -ln when my docker is running.
This has been finally identified as firewall issue and the ports can be accessed if the firewall rule is changed.

unable to connect to docker redis on windows from outside the docker instance

I've followed answers on other questions here on SO and via google but still unable to connect. Below is my attempt. I appreciate any suggestions to get this working.
Note all the firewalls are disabled during this test.
PS C:\WINDOWS\system32> docker run -d --name myredis -p 6379:6379 redis
Unable to find image 'redis:latest' locally
latest: Pulling from library/redis
f5d23c7fed46: Pull complete
a4a5c04dafc1: Pull complete
605bafc84bc9: Pull complete
f07a4e35cd96: Pull complete
17944e5e3eb7: Pull complete
6f875a8605e0: Pull complete
Digest: sha256:8888f6cd2509062a377e903e17777b4a6d59c92769f6807f034fa345da9eebcf
Status: Downloaded newer image for redis:latest
3f65a413985e513ef3e9a578b09a3c8729a214c767197d9e34268a38114e39c6
PS C:\WINDOWS\system32> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3f65a413985e redis "docker-entrypoint.s…" 7 seconds ago Up 6 seconds 0.0.0.0:6379->6379/tcp myredis
PS C:\WINDOWS\system32> docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' myredis
172.17.0.2
PS C:\WINDOWS\system32> docker exec -it myredis redis-cli
127.0.0.1:6379> ping
PONG
The above indicates (to me) that redis is running on the docker image and listening on port 6379 on both the docker image and host machine. From another powershell, I run redis client for windows and it just hangs
PS D:\Program Files\Redis> ./redis-cli
127.0.0.1:6379> connect 172.17.0.2 6379
The docker run -p option publishes the service's port on the host's IP address, and from outside of Docker you can connect to that. If you are specifically on the console of the same physical host running the container, you can use the special host name localhost or the matching special IPv4 address 127.0.0.1 to reach the container. (If you're inside a container, though, localhost usually means "this container".)
In your final redis-cli command where it says it's connected to 127.0.0.1:6379, you've already connected to the containerized Redis: you're done.
You never need the IP address returned by docker inspect, and it's unreachable in several very common setups; I would recommend never trying to look it up at all. If you're on a different host, or you're using Docker for Mac or Docker Toolbox, you will be unable to reach the Docker-private IP addresses, for example. The way you've done it with docker run -p is correct.

Container is not available on localhost in Windows Docker Toolbox

I try to connect to my container on localhost/127.0.0.1/0.0.0.0 but site can’t be reached.
Details:
$ docker run -d -p 80:80 nginx:alpine
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
d5b465ed1b18 nginx:alpine "nginx -g 'daemon of" 6 minutes ago Up 6 minutes 0.0.0.
0:80->80/tcp quizzical_swirles
798b40ceec77 10.36.7.241:5000/facileexplorer:0.3.8 "/usr/bin/supervisor" 9 minutes ago Up 9 minutes 4444/t
cp, 0.0.0.0:3838->3838/tcp, 0.0.0.0:8787->8787/tcp, 5900/tcp vigilant_banach
I followed this tutotial: https://blog.sixeyed.com/published-ports-on-windows-containers-dont-do-loopback/:
$ docker inspect --format '{{ .NetworkSettings.Networks.nat.IPAddress }}' d5b465ed1b18
<no value>
but it doesn't return port.
And I also helped myself with this guide: https://www.iancollington.com/docker-and-cisco-anyconnect-vpn/ because some of my docker images are on private registry, so I did following steps:
PATH=$PATH:"C:\Program Files\Oracle\VirtualBox"; export PATH
export DOCKER_HOST="tcp://127.0.0.1:2376"
docker-machine stop default
VBoxManage modifyvm "default" --natpf1 "docker,tcp,,2376,,2376"
docker-machine start default
alias docker='docker --tlsverify=false'
Could you help?
When you are using Docker Toolbox, running docker run -p 80:80 can be misleading. It means it will forward the port 80 of your container to the port 80 of your Docker machine, not the Windows host!
If you want to access the container through your Windows host, you also need to forward port 80 of your Docker machine to that host.
I see you are using VirtualBox, which allows you to do that by adding an entry in Settings > Network > Advanced > Port Forwarding.
Example tutorial with images: https://www.howtogeek.com/122641/how-to-forward-ports-to-a-virtual-machine-and-use-it-as-a-server/

How to identify the docker host ip to use when running a jenkins container

I have docker machine installed on windows OS and have pulled in Jenkins image from docker hub. I then run the below commands:
docker volume created myjenkins-data
docker run -p 8080:8080 -p 50000:50000 -v myjenkins-data:/var/jenkins_home jenkins
I received the admin key for Jenkins in the logs. I've confirmed that my container is still running status:
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2854c7d83879 jenkins "/bin/tini -- /usr..." About a minute ago Up About a minute 0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp quizzical_cray
Now, I need to log into 8080 port to view the Jenkins web app. But I do not know which host ip to use. I identified the docker host ip with the command "docker-machine ip" and got the ip address: 192.168.99.100. But using 192.168.99.100:8080 did not bring up Jenkins app. I also tried using docker inspect to get the container's ip, but port 8080 didn't work on those ips as well. Which ip address do i use to see the Jenkins app that is running in the container?
First, double-check if http://localhost:8080 is not enough.
Hyper-V (through vpnkit, if you are using Docker for Windows) should have done the port-forwarding for you.
If you are using the legacy docker toolbox (VirtualBox), then you need port-forwarding (issue 4115).

How to access container's web application from host

I am running a site inside Docker container which exports following
https://172.17.0.2:8443/admin/ &
http://172.17.0.2:8463/users/
$ docker run -it -d --expose=8000-9900 ubuntu-java8-webapp
bf193d011fd8....
Docker PS cmd
$ docker ps -a
CONTAINER ID IMAGE COMMAND PORTS NAMES
bf193d011fd8 ubuntu-.... "/bin/bash" 8000-9900/tcp desperate_mclean
Docker ls cmd
$ docker-machine ls
NAME ACTIVE DRIVER STATE URL DOCKER ERRORS
default * virtualbox Running tcp://192.168.99.100:2376 v1.10.3
Docker machine ip cmd
$ docker-machine ip default
192.168.99.100
How do I access the site? Just in case it matters, I am running docker on Mac here.
You can try and access it through the docker machine IP:
https://192.168.99.100:8443/admin
http://192.168.99.100:8463/users
But ideally, you would:
map those port to the host:
docker run -p 8443:8443 -p 8463:8463 ...
port-forward those port to your actual host through VirtualBox VM Network setting, and access the site with:
https://localhost:8443/admin
http://localhost:8463/users

Resources