D
D
Dauren S2022-01-04 11:18:29
Docker
Dauren S, 2022-01-04 11:18:29

Docker container access?

Hello everyone, I wanted to ask. Deployed 2 containers in one python, in the second redis. All on the same host. From the first I try to get access to redis but the connection does not go. does it need to be linked? I just wanted to use the radish container as a common bus, I don’t want to prescribe a link to it in all other containers.

in radish container
protected-mode no
bind 0.0.0.0 ::
bind 127.0.0.1 ::1
bind * ::1

Also opened port 6379

[email protected]:/data# nmap -sT -sU -p- 127.0.0.1
Starting Nmap 7.80 ( https://nmap.org ) at 2022-01-04 12:24 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00032s latency).
Not shown: 131069 closed ports
PORT STATE SERVICE
6379/tcp open redis

docker-compose.yml #redis

version: '3.6'

services:
   
    redis:
      
      image: 'redis_update'
      user: root
      restart: always
      ports:
        - 6379:6379
      
      volumes:
        - ./conf:/opt/local/bitnami/redis/etc
      
      environment:
          - ALLOW_EMPTY_PASSWORD=yes
      networks:
          - back
networks:
  back:
      # use a custom driver, with no options
      driver: bridge


docker-compose.yml #python
# docker-compose.yml

version: '3.8'

services:
  web:
    build: .
    command: uvicorn app.main:app --host 0.0.0.0 --reload
    volumes:
      - .:/code
    ports:
      - 8008:8000
    networks:
      - back
networks:
  back:
      # use a custom driver, with no options
      driver: bridge


#requirements.txt
asyncpg==0.22.0
fastapi==0.63.0
uvicorn==0.13.4
strawberry-graphql
requests
http3
celery
redis


main.py
import strawberry
import requests
from fastapi import FastAPI
from strawberry.fastapi import GraphQLRouter
import http3
import redis
client = http3.AsyncClient()

r = redis.Redis(
    host='redis_redis_1',
    port=6379)


app = FastAPI()
@app.get("/")
def read_root():
    
    value = r.get('mykey') 
    print(value)
    return {"Hello": "World2"}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
D0001, 2022-01-04
@dauren101

Make a shared network

G
Griboks, 2022-01-04
@Griboks

Usually open ports and prescribe them in other containers (like localhost:). For convenience, you can configure containers through environment variables or launch arguments.
It also makes sense to look towards docker swarm or compose.

A
Alexander Karabanov, 2022-01-04
@karabanov

Launch containers with docker-compose, then they will automatically be connected to the same virtual network and will be able to freely exchange traffic.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question