3

Based on this tutorial https://www.youtube.com/watch?v=XrFeRwJjWHI , I tried running Redis in Docker.

File docker-compose.yml

version: "3.8"

services:
  redis:
    image: redis
    volumes:
      - ./data:/data
    ports:
      - 6379:6379
docker pull redis
docker-compose up
docker-compose up -d
docker container ls
telnet localhost 6379

Telnet, type PING then press Enter key (you will not see text), then see result: PONG. Type quit to exit.

Microsoft Windows [Version 10.0.19041.508]
(c) 2020 Microsoft Corporation. All rights reserved.

D:\docker>docker-compose stop redis
Stopping docker_redis_1 ... done

D:\docker>

See what is running

docker container ls

You will see, docker redis was stoped.

docker image prune -a
docker-compose up

Docker RedisInsight

docker run -v redisinsight:/db -p 8001:8001 redislabs/redisinsight:latest

Wait about 6 minutes (at internet speed at 22:30) for downloading, unzip, install, starting.

go to: http://localhost:8001/ (auto open web browser). Health check for RedisInsight http://localhost:8001/healthcheck/ is OK.

enter image description here

enter image description here

enter image description here

(I also noted at here https://donhuvy.github.io/redis/docker/2020/10/10/run-redis-on-docker.html )

How to connect RedisInsight with Redis without error?

Update: This is my host file, seemly have problem at here (IP 127.0.0.1 for Kubernetes, really I don't know about Kubernetes, I am learning it.), but I don't know how to fix.

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost

127.0.0.1    www.techsmith.com
127.0.0.1    activation.cloud.techsmith.com
127.0.0.1    oscount.techsmith.com
127.0.0.1    updater.techsmith.com
127.0.0.1    camtasiatudi.techsmith.com
127.0.0.1    tsccloud.cloudapp.net
127.0.0.1    assets.cloud.techsmith.com

# Added by Docker Desktop
192.168.1.44 host.docker.internal
192.168.1.44 gateway.docker.internal
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section

Vy Do
  • 46,709
  • 59
  • 215
  • 313
  • Are these containers running in the same network? Try to list the networks and the containers to see if these are on the same network – Eitank Oct 10 '20 at 16:56
  • How to list the networks and the containers? – Vy Do Oct 10 '20 at 17:02
  • Did you get your answer? – Eitank Oct 11 '20 at 18:38
  • I am not sure . – Vy Do Oct 12 '20 at 01:25
  • 1
    you can do the following to list networks with docker: `docker network ls`. to check the network of your container you can do the following: `$ docker inspect c1 -f "{{json .NetworkSettings.Networks }}"` c1 == the name of the container. – Eitank Oct 12 '20 at 13:46
  • I catch error https://user-images.githubusercontent.com/1328316/95754071-b5ecf880-0ccc-11eb-9da0-e591ebe6c121.png – Vy Do Oct 12 '20 at 13:51

6 Answers6

9

Using this setup in docker-compose.yml

version: '3.7'

services:
  redis:
    image: 'redis:6.0.6'
    ports:
      - '127.0.0.1:6379:6379/tcp'
    volumes:
      - 'redis_data:/data:rw'
    healthcheck:
      test: redis-cli ping
      interval: 3s
      timeout: 5s
      retries: 5

  redisinsight:
    image: 'redislabs/redisinsight:latest'
    ports:
      - '127.0.0.1:8001:8001'

you can access redis via

enter image description here

Artem Bernatskyi
  • 4,185
  • 2
  • 26
  • 35
6

RedisInsight are trying to connect to container's localhost. Try typing 127.0.0.1 into Host field.

If file host has been changed like the updated information in question, use 192.168.1.44 .

Vy Do
  • 46,709
  • 59
  • 215
  • 313
n0nvme
  • 1,248
  • 8
  • 18
  • It still error https://user-images.githubusercontent.com/1328316/95660345-68984c00-0b51-11eb-8f2d-60ea97a970e3.png . I hope you can help me. – Vy Do Oct 10 '20 at 16:36
  • This is my host file https://gist.github.com/donhuvy/32aaf97a4e3e8b7cdacec53aab04d31d#file-hosts-txt-L35 seemly have problem at this IP. Let's me know how to fix. – Vy Do Oct 10 '20 at 16:38
  • 2
    @DoNhuVy according to your hosts file the IP address you are looking for is: `192.168.1.44` – n0nvme Oct 10 '20 at 16:47
4

For your containers to access each other you should first connect them to same network.

docker network create redis
docker network connect redis elastic_diffie
docker network connect redis docker_redis_1

After that open RedisInsight UI and write docker_redis_1 to your Hostand keep the port same. You should be able to connect to your redis container.

Selçuk
  • 1,088
  • 1
  • 8
  • 12
4

Since you haven't mentioned any network for the containers, they are conneted to the default bridge network. learn more

To get container IP address

Type in your terminal

# Check container network IP address

docker container inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" <container name>

Use the IP address in: http://localhost:8001/ (RedisInsight).

or

(Not Recommended) Type the IP address of your HOST machine will solve the problem

Use ipconfig or ifconfig based on your OS to get your IP

indrodev
  • 41
  • 2
1

I'm a little late to this one, but you can just use the docker host loopback

host.docker.internal - this will resolve to the host ip

enter image description here

aBetterGamer
  • 5,119
  • 2
  • 18
  • 19
-1

you must put your Ip by ipconfig instead of localhost

zhaleh
  • 11
  • 2