Home > front end >  Docker communication from one container to another
Docker communication from one container to another

Time:01-24

I have two docker containers. I'm trying to curl between one and the other container.

I've set up a common network.

Here is my docker-compose:

version: '3.8'
services:
  web:
    build: ./webapp/.
    container_name: storyweb
    command: python3 /app/manage.py runserver 0.0.0.0:8000
    volumes:
      - ./webapp/:/app/
    ports:
      - 8007:8000
    networks:
      - backend
    env_file:
      - ./.env.dev
  novnc:  
    container_name: dramatica
    build: ./dramatica/.
    environment:
      # Adjust to your screen size
      - DISPLAY_WIDTH=1200
      - DISPLAY_HEIGHT=800
      - PUID=1000
      - PGID=1000
    ports:
      - "8008:8080"
    volumes:
      - ./dramatica:/app
    networks:
      - backend
    restart: unless-stopped
    depends_on:
      - web 
    entrypoint: /app/entrypoint.sh
networks:
  backend:
    driver: bridge

I'm tryin gto curl from inside vovnc container:

curl -i web:8007

I've also tried storyweb.

Any idea why this is not working?

CodePudding user response:

When your server container runs a server process

python3 /app/manage.py runserver 0.0.0.0:8000

connections between containers need to go to that port 8000. ports: aren't used or required here, and can be removed if you don't require the service to be directly accessible from outside containers on the same Docker network.

CodePudding user response:

If you are trying the command curl -i web:8007 from your host machine. It will not work. You try this command from inside a container. You can try the following method

  1. curl -i localhost:8007
  2. docker-compose novnc curl -i web:8007r
  • Related