I am trying to connect to redis containers together to share some data, but I'm not having much luck. First I create a new docker container:
➜ docker-react git:(master) ✗ docker run -d --name red1 -v ~/vol:/data redis
7cec6f4fce354c3c603ef36813d9b8f41b446278b76bc8f05a901980bb864241
➜ docker-react git:(master) ✗ docker run -d --name red2 -v ~/vol:/data redis
566d4728cd8d2548a1ba4631bb118699157e03aae32a4566370fafdfae93463d
➜ docker-react git:(master) ✗ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
566d4728cd8d redis "docker-entrypoint.s…" 9 seconds ago Up 8 seconds 6379/tcp red2
7cec6f4fce35 redis "docker-entrypoint.s…" 20 seconds ago Up 19 seconds 6379/tcp red1
But when I go into 1 container and set some data, for example:
➜ docker-react git:(master) ✗ docker exec -it 566d4728cd8d redis-cli
127.0.0.1:6379> SET name Jim
OK
127.0.0.1:6379> SET age 20
OK
127.0.0.1:6379> get name
"Jim"
127.0.0.1:6379>
and then I go into the 2nd container, it is oblivious to the data:
➜ docker-react git:(master) ✗ docker exec -it 7cec6f4fce35 redis-cli
127.0.0.1:6379> get name
(nil)
127.0.0.1:6379>
Why? How can I connect these 2 containers to share the same data?
For me it looks like you are just launching two container of redis using the same volume. Have you setup those instances to store the data at the volumes location?
Related
I am new to docker. I installed docker on Windows 10. Also, I have installed SSH on my win.
I have a pylucene docker container. When I check the status of my docker container, it is Up.
PS C:\Windows\system32> docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d70d6f0ed7ab coady/pylucene "/bin/bash" 4 weeks ago Up 3 hours amazing_dubinsky
Also, I have no problem with executing it and working with its shell.
PS C:\Windows\system32> docker exec -it d70d6f0ed7ab /bin/bash
root#d70d6f0ed7ab:/usr/src# python
Python 3.9.2 (default, Mar 31 2021, 12:13:11)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lucene
>>> print(lucene.VERSION)
8.8.1
>>>
but when I found its IP and try to ping this docker container from my win, the result is just timeout!
PS C:\Windows\system32> docker inspect -f "{{ .NetworkSettings.IPAddress }}" d70d6f0ed7ab
172.17.0.3
PS C:\Windows\system32> ping 172.17.0.3
Pinging 172.17.0.3 with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Ping statistics for 172.17.0.3:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
PS C:\Windows\system32>
Also SSH connect to this container fails,
PS C:\Windows\system32> ssh root#172.17.0.3
ssh: connect to host 172.17.0.3 port 22: Connection timed out
PS C:\Windows\system32>
The coady/pylucene image is based on python:latest
python:latest is based on buildpack-deps:buster
buildpack-deps:buster is based on buildpack-deps:scm
buildpack-deps:scm is based on buildpack-deps:buster-curl
buildpack-deps:buster-curl is based on debian:buster
debian:buster is based Debian 10
And... debian 10 does not have openssh-server installed/active by default.
Plus, as mentioned here:
Docker Desktop for Windows can’t route traffic to Linux containers.
However, you can ping the Windows containers.
In other words, those "problems" you are experiencing are perfectly expected.
I have question about docker redis-sentinel:5.0.10 startup issue.
I am running docker on CentOS7 Linux.
Before 5.0.10 version I used 4.0.9 and image was taken from our own repository, now I switched to bitnami repo.
The main problem is that I try to use redis-sentinel:5.0.10 (or redis-sentinel:5.0.7) and it falls into restart loop and cannot start properly.
I run containers like that:
[root#XXX opt]# docker run -d -p 26380:26379 -v /opt/app/redis:/data --name redis-sentinel -e REDIS_MASTER_HOST=XXX.XXX.XXX -e REDIS_MASTER_SET=XXX-XXX -e REDIS_SENTINEL_DOWN_AFTER_MILLISECONDS=30000 -e REDIS_SENTINEL_QUORUM=2 -e REDIS_SENTINEL_FAILOVER_TIMEOUT=180000 --net=host --restart=always bitnami/redis-sentinel:5.0.10
[root#XXX opt]# docker run -d --net=host -v /opt/app/redis:/data -v /opt/app/redis.conf:/usr/local/etc/redis/redis.conf --name redis-client --restart=always redis:5.0.10-alpine redis-server --slaveof XXX.XXX.XXX 6379
In log there are messages like:
redis-sentinel 10:16:50.45 Welcome to the Bitnami redis-sentinel container
redis-sentinel 10:16:50.45 Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-redis-sentinel
redis-sentinel 10:16:50.45 Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-redis-sentinel/issues
redis-sentinel 10:16:50.46
redis-sentinel 10:16:50.46 INFO ==> ** Starting Redis sentinel setup **
redis-sentinel 10:16:50.47 ERROR ==> The configuration file /opt/bitnami/redis-sentinel/etc/sentinel.conf is not writable
Why it is not writable?
[root#dam31 ~]# docker run --rm -it bitnami/redis-sentinel:5.0.10 sh
redis-sentinel 14:03:36.16
redis-sentinel 14:03:36.16 Welcome to the Bitnami redis-sentinel container
redis-sentinel 14:03:36.17 Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-redis-sentinel
redis-sentinel 14:03:36.17 Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-redis-sentinel/issues
redis-sentinel 14:03:36.17
$ cd /opt/bitnami/redis-sentinel/etc/
$ ls -l
total 12
-rw-rw-r-- 1 root root 9797 Dec 8 13:25 sentinel.conf
docker ps command says:
[root#XXX app]# docker ps --no-trunc
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
45988acb45407dfc7a19f4a2a08da7c8f7a99381a97bc17a3ae985d377605462 redis:5.0.10-alpine "docker-entrypoint.sh redis-server --slaveof XXX.XXX.XXX 6379" 4 minutes ago Up 3 minutes redis-client
94b9b8e712e2219bc3f9a18aba349985968e3410c5336905282fb43b38e89e8e bitnami/redis-sentinel:5.0.10 "/opt/bitnami/scripts/redis-sentinel/entrypoint.sh /opt/bitnami/scripts/redis-sentinel/run.sh" 4 minutes ago Restarting (1) 19 seconds ago redis-sentinel
On other machines I have upgraded redis to 5.0.7 version successfully and it runs properly, nothing was done otherwise:
[root#XXX app]# docker ps --no-trunc
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
07e535350c02a67478dd07708a06798981fe7e99ae448567837dacdee198ec1e redis:5.0.7-alpine "docker-entrypoint.sh redis-server /usr/local/etc/redis/redis.conf --slaveof XXX.XXX.XXX 6379" 8 weeks ago Up 8 weeks redis-client
fea1bff3b2c1fbc9c7cea2becad64b7e2727dfc1f73f1d541e08b9b75143b3a9 bitnami/redis-sentinel:5.0.7 "/entrypoint.sh /run.sh" 8 weeks ago Up 8 weeks redis-sentinel
If I run on the same machine (where I tried to run redis:5.0.10) redis:5.0.7 the same error occured:
[root#XXX ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
15cdd46fa325 redis:5.0.7-alpine "docker-entrypoint.s…" 15 minutes ago Up 15 minutes redis-client
b0b02a36b68c bitnami/redis-sentinel:5.0.7 "/entrypoint.sh /run…" 16 minutes ago Restarting (1) 50 seconds ago redis-sentinel
redis-sentinel 14:16:23.86 Welcome to the Bitnami redis-sentinel container
redis-sentinel 14:16:23.87 Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-redis-sentinel
redis-sentinel 14:16:23.87 Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-redis-sentinel/issues
redis-sentinel 14:16:23.87 Send us your feedback at containers#bitnami.com
redis-sentinel 14:16:23.87
redis-sentinel 14:16:23.87 INFO ==> ** Starting Redis sentinel setup **
redis-sentinel 14:16:23.88 ERROR ==> The configuration file /opt/bitnami/redis-sentinel/etc/sentinel.conf is not writable
What I am doing wrong? Any thoughts? (NB! SELinux is disabled)
I have a docker image based on jenkins/jenkins:lts-alpine. For some reason, it is not able to resolve DNS names, as shown below:
[root#inf-jenkins02-prd ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
716ceece2017 myjenkins/jenkins:latest "/sbin/tini -- /us..." 12 minutes ago Up 12 minutes 8080/tcp, 50000/tcp jenkins_main.1.heaupued6g8eygrgrk6c8hlvy
[root#inf-jenkins02-prd ~]# docker exec -ti 716ceece2017 nslookup www.google.com
nslookup: can't resolve '(null)': Name does not resolve
nslookup: can't resolve 'www.google.com': Try again
[root#inf-jenkins02-prd ~]#
However, running the following works as expected:
[root#inf-jenkins02-prd ~]# docker run myjenkins/jenkins:latest nslookup google.com
nslookup: can't resolve '(null)': Name does not resolve
Name: google.com
Address 1: 216.58.204.142 par21s05-in-f142.1e100.net
Here is the Dockerfile use to build the image:
FROM jenkins/jenkins:lts-alpine
ENV JAVA_OPTS="-Djenkins.install.runSetupWizard=false -Dhudson.DNSMultiCast.disabled=true -Dhudson.udp=-1"
USER jenkins
RUN ssh-keygen -q -t rsa -N '' -f /var/jenkins_home/.ssh/id_rsa
COPY security.groovy /usr/share/jenkins/ref/init.groovy.d/security.groovy
COPY xlocation.groovy /usr/share/jenkins/ref/init.groovy.d/xlocation.groovy
COPY znodes.groovy /usr/share/jenkins/ref/init.groovy.d/znodes.groovy
COPY plugins.txt /usr/share/jenkins/ref/plugins.txt
RUN /usr/local/bin/install-plugins.sh < /usr/share/jenkins/ref/plugins.txt
And this is the docker-compose file:
version: "3.1"
services:
main:
container_name: jenkins-mine
image: myjenkins/jenkins
deploy:
placement:
constraints:
- node.role == manager
ports:
- 8080:8080
- 50000:50000
volumes:
- /home/jenkins:/var/jenkins_home/
- /var/run/docker.sock:/var/run/docker.sock
Then, I'm just doing:
docker stack deploy -c /.../docker-compose.yml jenkins
Everything seems to be okay:
[root#inf-jenkins02-prd ~]# docker service ls
ID NAME MODE REPLICAS IMAGE
71h4jrygqp7m jenkins_main replicated 1/1 myjenkins/jenkins
[root#inf-jenkins02-prd ~]# docker service ps 71h4jrygqp7m
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
heaupued6g8e jenkins_main.1 myjenkins/jenkins inf-jenkins02-prd Running Running 23 minutes ago
[root#inf-jenkins02-prd ~]#
but google.com can't resolve:
[root#inf-jenkins02-prd ~]# docker exec -ti 716ceece2017 nslookup www.google.conf
nslookup: can't resolve '(null)': Name does not resolve
nslookup: can't resolve 'www.google.conf': Try again
[root#inf-jenkins02-prd ~]# docker exec -ti 716ceece2017 cat /etc/resolv.conf
search ...
nameserver 127.0.0.11
options ndots:0
[root#inf-jenkins02-prd ~]#
Any idea of what's happening here ? Many thanks in advance.
Kind regards,
Nicolas
If you ever see the message nslookup: can't resolve '(null)': Name does not resolve, it's because nslookup is looking up the name of the server you're going to send the DNS query to. Since you didn't provide one, it's null. This is a known issue in nslookup (see https://github.com/gliderlabs/docker-alpine/issues/476). See also this SO question for more details..
One thing to check is that you're looking up the right domain.
Here, you looked up www.google.conf, not www.google.com. www.google.conf does not exist, so the output you got is expected.
# docker exec -ti 716ceece2017 nslookup www.google.conf
nslookup: can't resolve '(null)': Name does not resolve
nslookup: can't resolve 'www.google.conf': Try again
Another thing to check is to try nslookup with a different DNS resolver.
For example:
docker exec -ti 716ceece2017 nslookup www.google.conf 8.8.8.8
Then you can see if the issue is the Internet, or the DNS server.
I have the following setup:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
eab42051ca26 web-www:20180804 "node run.js" 8 minutes ago Up 8 minutes 3000/tcp web-www
63ec48e93a77 jwilder/nginx-proxy:latest "/app/docker-entrypo…" 9 hours ago Up 9 hours 0.0.0.0:80->80/tcp nginx-proxy-server
463ffd55260b fiorix/freegeoip "/go/bin/freegeoip" 9 hours ago Up 9 hours 8080/tcp freegeoip
bdc702c370ec euvat "/usr/local/bin/euva…" 9 hours ago Up 9 hours 3000/tcp euvat
40c07de732fa redis:4.0.10 "docker-entrypoint.s…" 9 hours ago Up 9 hours 6379/tcp redis-www
76831834f59d mongo:4.0 "docker-entrypoint.s…" 9 hours ago Up 9 hours 27017/tcp mongo-www
where my web-www node.js app connects to redis and mongo via the
NETWORK ID NAME DRIVER SCOPE
74d8f38aca38 bridge bridge local
1c894a7fa176 host host local
ca02c5ccac55 network-www bridge local
7226d9cc5360 none null local
my run.sh file is like:
OLDAPP="$(docker ps --all --quiet --filter=name="$APP")"
if [ -n "$OLDAPP" ]; then
docker stop $OLDAPP && docker rm $OLDAPP
fi
docker run --name web-www \
--network network-www \
--link euvat:euvat \
--link freegeoip:freegeoip \
--env VIRTUAL_HOST=araweelo.local \
--env-file /env/web-www.env \
web-www:20180804.182446
so, now i am starting a new development stack dev-www for example, so i will create the network-dev, launch redis-dev and mongo-dev but want to share the euvat and freegeoip containers with the web-www container.
is this the correct way to do this or is there an alternative method?
any advice is much appreciated.
Docker links are deprecated and maybe removed soon.
It's better to create the networks, containers ahead of time and join the container to the network
docker network create network-www
docker run --name web-www \
--env VIRTUAL_HOST=araweelo.local \
--env-file /env/web-www.env \
web-www:20180804.182446
docker network connect network-www web-www
docker network connect network-www euvat
docker network connect network-www freegeoip
This above commands will create a network-www user-defined bridge network and connect euvat, web-www and freegeoip containers to that network.
Replace/add containers as required. Might be a better idea to write a compose file which brings up the containers in a single command
I'm running aerospike server in docker.
$ docker run -d --name aerospike aerospike/aerospike-server
0ad3b2df67bd17f896e87ed119758d9af7fcdd9b82a8632828e01072e2c5673f
It is started successfully.
$docker ps
CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS NAMES
0ad3b2df67bd aerospike/aerospike-server "/entrypoint.sh asd"
4 seconds ago Up 2 seconds 3000-3003/tcp aerospike
I found the ip address of docker using below command.
$ docker inspect -f '{{.NetworkSettings.IPAddress }}' aerospike
172.17.0.2
When I trying to connect to aql using the below command, it is successful as well.
$ docker run -it aerospike/aerospike-tools aql -h $(docker inspect -f
'{{.NetworkSettings.IPAddress }}' aerospike)
Aerospike Query Client
Version 3.15.0.3
C Client Version 4.2.0
Copyright 2012-2017 Aerospike. All rights reserved.
aql> select * from test.person
0 rows in set (0.002 secs)
Now I am trying to connect to the aerospike server in docker using java client in host machine.
public class AerospikeDemo {
public static void main(String []args) {
AerospikeClient client = new AerospikeClient("172.17.0.2", 3000);
Key key = new Key("test", "demo", "putgetkey");
//Key key2 = new Key("1", "2", "3");
Bin bin1 = new Bin("bin1", "value1");
Bin bin2 = new Bin("bin2", "value2");
Bin bin3 = new Bin("bin2", "value3");
// Write a record
client.put(null, key, bin1, bin2, bin3);
// Read a record
Record record = client.get(null, key);
System.out.println("record is "+ record);
System.out.println("record bins is " + record.bins);
client.close();
}
}
When I run the above program, I'm getting below error -
objc[3446]: Class JavaLaunchHelper is implemented in both
/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/java (0x10f7b14c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10f8794e0). One of the two will be used. Which one is undefined.
Exception in thread "main" com.aerospike.client.AerospikeException$Connection:
Error Code 11: Failed to connect to host(s): 172.17.0.2 3000 Error Code 11: java.net.SocketTimeoutException: connect timed out
at com.aerospike.client.cluster.Cluster.seedNodes(Cluster.java:413)
at com.aerospike.client.cluster.Cluster.tend(Cluster.java:306)
at com.aerospike.client.cluster.Cluster.waitTillStabilized(Cluster.java:271)
at com.aerospike.client.cluster.Cluster.initTendThread(Cluster.java:181)
at com.aerospike.client.AerospikeClient.<init>(AerospikeClient.java:210)
at com.aerospike.client.AerospikeClient.<init>(AerospikeClient.java:151)
at com.demo.aerospike.AerospikeDemo.main(AerospikeDemo.java:12)
I've tried both AerospikeClient("172.17.0.2", 3000) and AerospikeClient("localhost", 3000)
I see in the Dockerfile the port 3000 is exposed to the host but I'm not sure why I'm not able to use the aerospike server in the docker.
The IP 172.17.0.2 is only accessible within Docker (therefore you can use another container to connect). In case you want to connect from your host you need to map the respective port.
docker run -d --name aerospike -p 3000:3000 aerospike/aerospike-server
Afterwards you can use:
AerospikeClient client = new AerospikeClient("localhost", 3000);