Docker :: assign different IP address to each container on Synology NAS - docker

I'm getting familiar with Docker thanks to my NAS Syonlogy 1515+.
I have created a SQL Server 2019 container called sqlserver4 that listen on port 1433:
sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=My_Password" -p 1433:1433 --name sqlserver4 -d mcr.microsoft.com/mssql/server:2019-latest
And I have then created a second one called sqlserver5 that listen on port 1533:
sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=My_Password" -p 1533:1533 --name sqlserver5 -d mcr.microsoft.com/mssql/server:2019-latest
All good, my two servers are there at the IP Address 192.168.1.44
I can connect through SSMS to the first one, the sqlserver4:
But when I try to connect to the second one, the sqlserver5 I receive the error:
A connection was successfully established with the server, but then an
error occurred during the pre-login handshake. (provider: TCP
Provider, error: 0 - The specified network name is no longer
available.) (Microsoft SQL Server, Error: 64)
It's easy to see where the problem is: even if they are on different port, 1433 and 1533 the IP Address is always the same 192.168.1.44
How can I setup a different IP Address for each container?
EDIT:
#David Maze suggested me to stop sqlserver4 and try to connect to sqlserver5. My assumption was wrong, I cannot connect to sqlserver5 neither. But fun fact, the error changes:
A connection was successfully established with the server, but then an
error occurred during the pre-login handshake. (provider: TCP
Provider, error: 0 - An existing connection was forcibly closed by the
remote host.) (Microsoft SQL Server, Error: 10054)

Related

Memcached in standalone Docker container time out and port error

I'm running a setup of 3 Ubuntu virtual machines. Two running the Python production code base and the other has a Memcached Docker container. On the Memcached machine I ran docker run -dit --name production-memcached --publish 11211:11211 memcached:latest.
The code base gets the following error message when trying to interact with it:
"exception": "TimeoutError(10060, 'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond', None, 10060, None)"
I have ran docker exec -it production-memcached memcached stats and get the error message below.
failed to listen on TCP port 11211: Address already in use
However I've ran netstat -plnt and get tcp6 0 0 :::11211 :::* LISTEN 35030/docker-proxy, which looks fine to me.
I was able to get this to work by opening port 80 and using iptables to forward incoming port 80 to port 11211 but would prefer to use the Memcached port number.
The Memcached client is created by the following line:
client = base.Client(("domain.co.uk", 11211))
Any help would be appreciated, thanks.
DigitalOcean doesn't allow in-traffic on port 11211 to its virtual machines. If you want a Memcached machine you'll also need a virtual machine to act a proxy between you and it. I hope this saves someone the headache it caused me!

Docker tutorial, localhost:4000 is inaccessible

Following the tutorial on https://docs.docker.com/get-started/part2/.
I start my docker container with docker run -p 4000:80 friendlyhello
and see
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://0.0.0.0:8088/ (Press CTRL+C to quit)
But it's inaccessible from the expected path of localhost:4000.
$ curl http://localhost:4000/
curl: (7) Failed to connect to localhost port 4000: Connection refused
$ curl http://127.0.0.1:4000/
curl: (7) Failed to connect to 127.0.0.1 port 4000: Connection refused
Okay, so maybe it's not on my local host. Getting the container ID I retrieve the IP with
docker inspect --format '{{ .NetworkSettings.IPAddress }}' 7e5bace5f69c
and it returns 172.17.0.2 but no luck! curl continues to give the same responses. I can confirm something is running on 4000....
lsof -i :4000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
com.docke 94812 travis 18u IPv6 0x7516cbae76f408b5 0t0 TCP *:terabase (LISTEN)
I'm pulling my hair out on this. I've read through the troubleshooting guide and can confirm
* not on a proxy
* don't use a custom dns
* I'm having issues connecting to docker, not docker connecting to my pip server.
Running the app.py with python app.py the server starts and I'm able to hit it. What am I missing?
Did you accidentally put port=8088 at the bottom of your app.py file? When you are running this the last line of your output is saying that your python app is exposed on port 8088 not 80.
To confirm you can run either modify the app.py file and rebuild the image, or alternatively you could run: docker run -p 4000:8088 friendlyhello which would map your local port 4000 to 8088 in the container.
Try to run it using:
docker run -p 4000:8088 friendlyhello
As you can see from the logs, your app starts on port 8088, but you connect 4000 to 80 where on 80, nothing is actually listening.

Docker: ssh -L to docker container - connection refused

I'm having problems to get my ssh tunnel working for my container in a docker swarm cluster.
ssh connection on my local machine:
ssh -L 7180:test.XXX:7180 user#XXX
In my Dockerfile on the remote machine:
EXPOSE 7180
Container start:
docker -H test:2379 --tlsverify run -d -p 7180:7180 --net=my-net
I tried to connect in Firefox via:
localhost:7180
Unfortunately the connection gets refused on the remote machine:
channel 3: open failed: connect failed: Connection refused
"docker container ls" prints following for the ports:
xxx:7180->7180/tcp
Inside my container "netstat -ntlp | grep LISTEN" prints:
tcp 0 0 0.0.0.0:7180 0.0.0.0:* LISTEN -
I'm new to this but after all what I've read so far this should actually work. I'm using "--net=my-net" because I want to setup my own network later. I had the same issue with "--net=host". What am I doing wrong?
The ssh command should be:
ssh -L 7180:127.0.0.1:7180 user#XXX
And then from your browser, you would go to:
http://127.0.0.1:7180
I've avoided using "localhost" because some machines map this to IPv6 even if you don't have IPv6 configured.
When testing this tunnel, make sure your application is listening on the remote server by doing an ssh to that server and run a curl command directly on the server to 127.0.0.1:7180. If it doesn't work there, you would repeat your debugging with netstat inside the container and verifying the port is published in thedocker ps` output.
I got it working with
ssh -D localhost:7180 -f -C -q -N user#XXX
and using
xxx:7180
in my browser (instead of localhost).
localhost and --net=host did not work for me with ssh -L.

failed: port is already allocated

I use Docker for running Oracle 11g Express on macOS Sierra 10.12.2
https://github.com/wnameless/docker-oracle-xe-11g
This is my error:
Last login: Sat Jan 7 22:42:11 on ttys000
➜ ~ docker run -d -p 49160:22 -p 49161:1521 wnameless/oracle-xe-11g
docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?.
See 'docker run --help'.
➜ ~ docker run -d -p 49160:22 -p 49161:1521 wnameless/oracle-xe-11g
043d8caecbb45d6e2e5999b69a2f760c20d53ff3aa2fad78cb1eb70acb058a1f
docker: Error response from daemon: driver failed programming external connectivity on endpoint serene_lalande (08bb0bd9684c0f92db7b736986bf894d3a57a714324405823496d13e175e7491): Error starting userland proxy: Bind for 0.0.0.0:49161 failed: port is already allocated.
➜ ~
I diagnostic:
➜ ~ netstat -anp tcp | grep 49161
tcp4 0 0 192.168.1.2.49161 17.188.166.13.5223 ESTABLISHED
➜ ~
➜ ~ docker --version
Docker version 1.12.5, build 7392c3b
My Dianostic ID: 20EB9506-CC72-4093-8A15-60E05A841ED1
I don't know why. Before that few weeks, it run success. Nearly, I change, release new DHCP IP. How to run Docker instance has Oracle 11g express success?
you can't launch twice
docker run -d -p 49160:22
as this means you want to allocate the port 49160 on the host twice, of course, the second time, you get you error message, try for the second run
docker run -d -p 49161:22
You will need to use a different port instead of 49161. Try a port less than 49152.
You have a pre-existing connection between the the port 49161 on your computer and port 5223 on a remote Apple server. That port, therefore, cannot be used for anything else until that connection ceases to exist. Port 5223 is used for Apple's push notifications. As best as I can tell, your computer so happened to use the random port 49161 to connect to Apple's server this time. Previously when that Docker container worked, I would bet port 49161 on your computer was not then used.
Whenever you connect to a remote server, your own computer allocates a random port number for that connection. This time around, your computer allocated 49161 when it connected to Apple's push notifications service. Next time, it could be a completely different number. See https://en.wikipedia.org/wiki/Ephemeral_port

How to connect a service running inside a docker with consul?

I am trying to run a docker container that takes the CONSUL_URL as an ENV Variable. For now, I have set up the consul on my localhost and I run it like this: consul agent -dev -bind=127.0.0.1 -ui-dir /usr/local/Cellar/consul/0.7.0/share/consul/web-ui
I am able to access the consul ui this way when I go to http://localhost:8500. But, now that I am running the docker container through this, docker run -e CONSUL_URL=127.0.0.1:8500 -p 8500:8500 b321825a6c7a, it gives me the following error:
2016/10/05 09:38:38 [ERR] (view) "key_or_default(foo.appconfig.properties/logger.name, "foo_PERF_LOG")" store key: error fetching: Get http://127.0.0.1:8500/v1/kv/foo.appconfig.properties/logger.name?stale=&wait=60000ms: dial tcp 127.0.0.1:8500: getsockopt: connection refused
2016/10/05 09:38:38 [ERR] (runner) watcher reported error: store key: error fetching: Get http://127.0.0.1:8500/v1/kv/foo.appconfig.properties/logger.name?stale=&wait=60000ms: dial tcp 127.0.0.1:8500: getsockopt: connection refused
Consul Template returned errors:
store key: error fetching: Get http://127.0.0.1:8500/v1/kv/foo.appconfig.properties/logger.name?stale=&wait=60000ms: dial tcp 127.0.0.1:8500: getsockopt: connection refusedexecuting: 'myscript.sh run'
Why am I not able to connect with the consul URL? I also tried changing the localhost url to the IP Address of my machine, but, I get the same error with that too. I have done the port mapping, so, I guess it should work. Where am I going wrong?
You have to use the --net=host flag.
This flag will create sockets for the exposed ports for all interfaces in the main OS.
docker run --net=host -e CONSUL_URL=127.0.0.1:8500 b321825a6c7a

Resources