I am using windows10, redis-64bit, I started a redis container with command:
docker run --name myredis -d redis redis-server --appendonly yes
when I try to connect to this container using:
redis-cli -h 192.168.99.1 -p 6379
it shows:
Could not connect to Redis at 192.168.99.1:6379: Unknown error
here, 192.168.99.1 is my virtual machine ip address, anyone know how to solve this issue, thanks!
To connect to a redis container from a remote server you should do the following:
Start redis container on host (192.168.99.1):
docker run --name myredis -p 7000:6379 -d redis redis-server
Connect via remote server:
redis-cli -h 192.168.99.1 -p 7000
Related
docker run --rm -it --name ucp -v /var/run/docker.sock:/var/run/docker.sock docker/ucp install -i --swarm-port 3376 --controller-port 4443
How to install Docker UCP and DTR installation on AWS EC2 instance. How to access UCP UI?
When am trying to install using above command, UCP getting installed on Private IP of the EC2 instance? How can I access UCP UI using private IP of EC2?
You forgot to specify host IP, see example below:
docker container run -e UCP_ADMIN_PASSWORD=passwd \
--name ucp -v /var/run/docker.sock:/var/run/docker.sock docker/ucp install \
--host-address 54.xxx.xxx.xx --controller-port 443
Then just load the UCP using your public IP and port 443.
I'm trying a simple setup with a docker postgres image, publishing a port for me to connect from the localhost.
docker run -p 5432:5432 --name postgres -e POSTGRES_PASSWORD=password -e POSTGRES_USER=postgres -d postgres
I'm able to connect just fine if I specify the docker external IP:
psql -h 192.1469.99.100 -p 5432 -U postgres -d postgres --password
However I get a password authentication failure when trying against localhost:
psql -h localhost -p 5432 -U postgres -d postgres --password
psql: FATAL: password authentication failed for user "postgres"
Do I need to set up some manual port forwarding manually? The weird thing is that it seems to connect to the postgres server just fine, it's just bizarrely telling me the password fails. I've done something wrong with the docker config perhaps?
The pg_hba.conf looks like:
local all all trust
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
The host machine is Windows 7.
Did you try another port than 5432? Try some free port so that there is no conflict between your local postgre and your docker postgre. To me it looks like your local postgre is having higher prio on localhost:5432, takes the traffic and so you are trying to login to your local postgre instead of your docker postgre, but obv. just a guess.
Did you check if you have this port allowed in the virtual machine or whatever you use for virtualization?
The container has its own network and its loopback address does not refer to the host and vice versa.
Mac running Docker Version 17.12.0-ce-mac55 (23011) here.
I have a very bizarre situation with Docker that I absolutely cannot explain!
I have a Dockerized web service that runs perfectly fine outside of Docker, running off of port 9200 (so: http://localhost:9200)
I can also run several other images locally (nginx, Oracle DB) and I can access them via localhost:80 and localhost:1521 respectively
When I run the container for my Dockerized service, I see (via docker logs <containerId>) the service startup without any errors whatsoever
Despite the fact that the container is running without any errors, I absolutely cannot connect to it from my Mac host via localhost:9200
The exact steps to reproduce are:
Clone this repo
Build the image via ./gradlew clean build && docker build -t locationservice .
Run the container via docker run -it -p 9200:9200 -d --net="host" --name locationservice locationservice
If you use docker ps to obtain the <containerId>, then you can keep hitting docker logs <containerId> until you see it has started up without errors
On my machine, when I try to curl against localhost:9200, I get "connection refused" errors (see below)
curl error is:
curl -X GET http://localhost:9200/bupo
curl: (7) Failed to connect to localhost port 9200: Connection refused
Some things I have ruled out:
localhost is absolutely resolveable from the host because we're running in host network mode and I have no problem connecting to nginx (port 80) and Oracle (port 1521) containers
The app is starting up and if you look at the logs you'll see it is starting up listening on 9200
Any ideas what the problem could be?!
Docker for Mac runs in a VM. --net=host refers to the Linux VM hosts network stack not OSX. There is no direct network path from OSX to the Docker VM other than mapped ports.
Mapped ports (docker run -p Y:N) in Docker for Mac are a little special, in addition to the user space proxy that runs on the Docker host normally, Docker for Mac also launches a user space proxy on OSX to listen on the same port and forward connections into the VM. The OSX process isn't started when using --net=host (and the Linux one isn't either of course).
→ docker run --name nc --rm --net=host -dp 9200:9200 busybox nc -lk -p 9201 -e echo hey
→ docker inspect nc --format '{{ json .NetworkSettings.Ports }}'
{}
→ sudo lsof -Pni | grep 9200
→
Then without --net=host
→ docker run --name nc --rm -dp 9200:9200 busybox nc -lk -p 9201 -e echo hey
→ docker inspect nc --format '{{ json .NetworkSettings.Ports }}'
{"9200/tcp":[{"HostIp":"0.0.0.0","HostPort":"9200"}]}
→ sudo lsof -Pni | grep 9200
vpnkit 42658 matt 28u IPv4 0x57f79853269b81bf 0t0 TCP *:9200 (LISTEN)
vpnkit 42658 matt 29u IPv6 0x57f798532765ca9f 0t0 TCP [::1]:9200 (LISTEN)
If your app requires --net=host then I would use Vagrant/Virtualbox to spin up a VM with a "Host Only" adapter. This means there is a direct network path that you can access from OSX on the VM. Here's the Vagrantfile I use.
Docker for Mac does not support host network mode very well: https://github.com/docker/for-mac/issues/1031
So at this moment the solution is to use default bridge mode.
I started to play around with docker for a while and got stuck with the below:
Here's my Environment:
Windows 10
boot2docker/Docker version 1.12.0
Virtual box 5.0.24
this is what i'm trying to do:
$ docker run -itp 8090:8090 lamp
root#8ebc390337be:/# service apache2 start
* Starting web server apache2 *
root#8ebc390337be:/# service mysql start
* Starting MySQL database server mysqld [ OK ]
root#8ebc390337be:/#
deattached from container and then
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8ebc390337be lamp "/bin/bash" 13 minutes ago Up 13 minutes 0.0.0.0:8090->8090/tcp happy_brown
$ docker inspect $(docker ps -q) | grep IPA
"SecondaryIPAddresses": null,
"IPAddress": "172.17.0.2",
"IPAMConfig": null,
"IPAddress": "172.17.0.2",
now when i try to run
$ curl 172.17.0.2:8090
curl: (7) Failed to connect to 172.17.0.2 port 8090: Timed out
then i tried
$ docker-machine ip default
192.168.99.100
$ curl 192.168.99.100:8090
curl: (7) Failed to connect to 192.168.99.100 port 8090: Connection refused
i did go through this accessing-a-docker-container-url-on-windows-host but it didn't help me.
i should be able to access the url from inside and outside the docker.
Could someone help me to troubleshoot
This is the ip address you should be using 192.168.99.100
I expect the problem is that your apache server is on port 80 inside the container, not 8090, i.e. your docker command should be:
$ docker run -itp 8090:80 linode/lamp
Which means map port 8090 on the outside host (192.168.99.100) to port 80 inside the container.
The latest release of Docker doesn't use a virtual machine anymore, instead using a hypervisor to connect to the containers. This means I can no longer login to postgres with psql:
➜ postgres git:(master) ✗ docker run -d -p 5433:5432 db postgres
<sha>
➜ postgres git:(master) ✗ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
111f3bed4c52 db "/docker-entrypoint.s" 17 minutes ago Up 17 minutes 0.0.0.0:5433->5432/tcp zen_hugle
➜ postgres git:(master) ✗ psql -p 5433 -U postgres
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5433"?
I have also tried specifying localhost as the host, but that results in a strange output:
➜ postgres git:(master) ✗ psql -h localhost -p 5433 -U postgres
psql: %
Does anyone know what to do in this case? Thank you.
With follwing command,
docker run -d -p 5433:5432 db postgres
You are exporting your docker's 5432 port to docker-engine's 5433 port. Not your host machine's 5433.
Fetch your docker-machine's IP address with following command (assuming your docker vm name is default)
docker-machine env default
This should give you result similar to following lines
> export DOCKER_TLS_VERIFY="1"
> export DOCKER_HOST="tcp://192.168.99.100:2376"
> export DOCKER_CERT_PATH="/Users/<your-user>/.docker/machine/machines/default"
> export DOCKER_MACHINE_NAME="default"
Use your docker-machine's IP address to connect to Postgres running in container
>psql -h 192.168.99.100 -p 5433 -U postgres
psql (9.5.0, server 9.5.5)
Type "help" for help.
postgres=#
You can connect over tcp by using an IP like psql -h 0.0.0.0 -p 5433 -U postgres (or 127.0.0.1, etc.).
Using the default or "localhost" will try using the local domain socket (although the version of Docker doesn't change this behavior, you will generally need to connect to a containerized db via tcp).