0

I'd like to be able to connect directly to the redis container below:

root $ 
root $ docker images redis
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
redis               alpine              bd71e6db4a54        2 weeks ago         32.2MB
redis               latest              84c5f6e03bf0        2 weeks ago         104MB
root $ 
root $ docker run --name rd -d -p 99:99 redis:latest
ac4b8b2b032b2c2911f03fd4f6af649f470620cd29eb566b821e5ce738d9ac11
root $ 
root $ docker exec -ti --user root rd bash
root@ac4b8b2b032b:/data# 
root@ac4b8b2b032b:/data# redis-cli
127.0.0.1:6379> 
127.0.0.1:6379> exit
root@ac4b8b2b032b:/data# 
root@ac4b8b2b032b:/data# exit
exit
root $ 
root $ docker network ls
NETWORK ID          NAME                    DRIVER              SCOPE
74c94db9195c        basexhttpnetwork        bridge              local
a5efbdf4bc39        bridge                  bridge              local
4b6586d1bc8c        frappe_docker_default   bridge              local
1b875368faa0        helloworld_default      bridge              local
3bc6659535b4        host                    host                local
e877e399bf78        none                    null                local
root $ 
root $ docker container ls
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                          NAMES
ac4b8b2b032b        redis:latest        "docker-entrypoint.s…"   6 minutes ago       Up 6 minutes        0.0.0.0:99->99/tcp, 6379/tcp   rd
root $ 

using the redis-cli tool from the host. So I would need to add or attach the rd (for redis) container to the bridge driver? Then specify an IP address and port from the host?

1

By default Docker uses the bridge network.

On a default Docker installation you can simply map a port to the container's service port. The Redis Docker image exposes its service on port 6379 so you can do:

$ docker run --name rd -d -p 6379:6379 redis:latest

From your host you can now run use the redis-cli utility:

$ redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>
0

tentative answer:

root $ 
root $ docker run --name rds -d redis redis-server --appendonly yes
d85ce8736fc33f81edc7e63972391f6eb34586d562b4066f57395f9ea2bafe58
root $ 
root $ docker container ls
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
d85ce8736fc3        redis               "docker-entrypoint.s…"   9 seconds ago       Up 6 seconds        6379/tcp            rds
root $ 
root $ docker exec -it rds redis-cli
127.0.0.1:6379> 
127.0.0.1:6379> keys *
(empty array)
127.0.0.1:6379> 
127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> 
127.0.0.1:6379> keys *
1) "foo"
127.0.0.1:6379> 
127.0.0.1:6379> get foo
"bar"
127.0.0.1:6379> 

should work as persistence in a microservice architecture. To my understanding.

root $ 
root $ docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
e57e2c862b19        bridge              bridge              local
25aba55a5413        host                host                local
ad5c1c2fa1e1        none                null                local
root $ 
root $ docker inspect rds | grep bridge
                "bridge": {
root $ 
root $ docker network inspect bridge
[
    {
        "Name": "bridge",
        "Id": "e57e2c862b19e68b470adf5bbd4719b675c15a399e3bd01380a9d7ad35c7ea26",
        "Created": "2020-09-24T17:43:14.098411476-07:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16",
                    "Gateway": "172.17.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "d85ce8736fc33f81edc7e63972391f6eb34586d562b4066f57395f9ea2bafe58": {
                "Name": "rds",
                "EndpointID": "b0afddd9a063d8051021db490342e6627bdf9694b8f526ad5bbd5a665eeafefd",
                "MacAddress": "02:42:ac:11:00:02",
                "IPv4Address": "172.17.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1500"
        },
        "Labels": {}
    }
]
root $ 

So a flask container also on the bridge network should be able to access this container.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.