skip to Main Content

I want to access the lowerquality/gentle container into my Django container. when I run the docker-compose up command I cannot access the gentle container by localhost:49153 I can access the localhost:49153 through my laptop but cannot access it inside the Django container.

Docker-compose file


version: '3.8'

services:
  web:
    build:
      context: ./app
      dockerfile: Dockerfile.prod
    # command: gunicorn core.wsgi:application --bind 0.0.0.0:8000
    command: bash -c "python manage.py migrate && gunicorn core.wsgi:application --bind 0.0.0.0:8000"
    volumes:
      - static_volume:/usr/src/app/staticfiles
      - media_volume:/usr/src/app/media
    expose:
      - 8000
    env_file:
      - ./.env.prod
    depends_on:
      - db
    ports:
      - 8000:8000
  db:
    restart: always
    image: postgres
    volumes:
      - postgres_data:/var/lib/postgresql/data/
    env_file:
      - ./.env.prod.db

  nginx:
    build: ./nginx
    volumes:
      - static_volume:/usr/src/app/staticfiles
      - media_volume:/usr/src/app/media
    ports:
      - 80:80
    depends_on:
      - web

  # redis:
  #   image: redis
  #   ports:
  #     - '6379:6379'
  #   expose:
  #     - 6379

  djangoq:
    build: ./app
    command: python manage.py qcluster
    volumes:
      - static_volume:/usr/src/app/staticfiles
      - media_volume:/usr/src/app/media
    depends_on:
      # - redis
      - web
      - gentle
    env_file:
      - ./.env.prod
    
  gentle:
    restart: always
    image: lowerquality/gentle
    ports:
      - '49153:8765'
    expose:
      - 49153

volumes:
  postgres_data:
  static_volume:
  media_volume:

Error accessing the gentle container inside the django container.

docker container error

I did change the URL path to localhost:49153 and gentle:49153 could not access

accessing from my laptop is working using localhost:49153

accessing container from laptop

I did try to access using localhost:49153, gentle:49153 and gentle

How can I access gentle container inside Django container?

2

Answers


  1. Containers can only communicate with each other if they share a network. Containers that don’t share a network cannot talk with one another. That’s one of the isolation features provided by Docker.

    Read his link for more information.

    You could add a network at the end of your docker-compose file.

    networks:
      default:
        external:
          name: <your_network_name>
    

    Note: You should create the network first.

    docker network create <your_network_name>
    

    After these changes, you can use a container or hostname of your container to connect to another container in the network.

    Note: run docker ps to see container names.

    Login or Signup to reply.
  2. The correct connection string is gentle:8765

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search