0

I want to start two apps on the same machine, one is ragflow the other is dify. Their docker-compose.yaml files both define the redis service.

Ragflow defines as following

  redis:
    # swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/valkey/valkey:8
    image: valkey/valkey:8
    container_name: ragflow-redis
    command: redis-server --requirepass ${REDIS_PASSWORD} --maxmemory 128mb --maxmemory-policy allkeys-lru
    env_file: .env
    ports:
      - ${REDIS_PORT}:6379
    volumes:
      - redis_data:/data
    networks:
      - ragflow
    restart: on-failure

Dify defines as following

  redis:
    image: redis:6-alpine
    restart: always
    environment:
      REDISCLI_AUTH: ${REDIS_PASSWORD:-difyai123456}
    volumes:
      # Mount the redis data directory to the container.
      - ./volumes/redis/data:/data
    # Set the redis password when startup redis server.
    command: redis-server --requirepass ${REDIS_PASSWORD:-difyai123456}
    healthcheck:
      test: [ 'CMD', 'redis-cli', 'ping' ]

I first started ragflow and set redis to map to host the port 6378, as docker ps show

92660bc83fb4   valkey/valkey:8  ...  0.0.0.0:6378->6379/tcp, [::]:6378->6379/tcp ragflow-redis                                                                                

I then started dify, but to my surprise it output

...
 ✔ Container ragflow-redis           Recreated                                                                                                                                 
 ✔ Container docker-redis-1          Started 

I then docker composer down them both, and started dify first then ragflow, but this time ragflow output

 ✔ Container docker-redis-1  Recreated                                                                                                                                        
 ✔ Container ragflow-redis   Started

Then I had thought maybe it was because dify's docker-composer.yaml did not define a container_name for redis, so I added container_name: dify-redis for it. But that did not work, when I start dify then ragflow, I still saw the output

 ✔ Container dify-redis      Recreated                                                                                                                                       
 ✔ Container ragflow-server  Started  

Only after I start them using --project-name they did start successfully.

docker compose --project-name dify up -d
docker compose --project-name ragflow up -d

But why does docker composer confuse them ? I check each networks setting and did not understand the reason.

# for ragflow
networks:
  ragflow:
    driver: bridge

# for dify
networks:
  ssrf_proxy_network:
    driver: bridge
    internal: true
  milvus:
    driver: bridge
  opensearch-net:
    driver: bridge
    internal: true

3
  • 1
    Compose uses the last level of the directory path as the default project name. It looks like one of them is in a 'docker' directory because it names the container docker-redis-1. If both compose files are in a directory named 'docker', compose might think they're part of the same project. See this. Commented Mar 24 at 13:52
  • Thanks for the reply. Yes, both are in a a directory named 'docker' and I also read something similar to the link you referred to so I added --project-name to make it work. But I feel it looks like a docker bug or least a quirk behaviour to me, e.g. container_name does not help here. Commented Mar 25 at 2:18
  • Compose adds the project name to the container as a label and I think that's what it uses to determine if containers belong to the same project. You can see the project name by running docker container inspect <container name>. If you want to extract the project name, you can do docker container inspect <container name> | jq '.[0].Config.Labels."com.docker.compose.project"' Commented Mar 25 at 7:50

1 Answer 1

0

With the comments I got from @HansKilian and some test I finally understand what happened.

The most revealing fact is to run ` docker compose ls`

sudo docker compose ls
NAME                  STATUS              CONFIG FILES
docker                running(14)         /home/ubuntu/dify/docker/docker-compose.yaml,/home/ubuntu/ragflow/docker/docker-compose.yml

So docker composer think they are the same project!

Both dify and rafglow has a "docker" folder, which docker-compose.yaml resides, no matter I start them from inside the docker folder or elsewhere, the project name is 'docker', so docker compose thinks they are the same project. Even though ragflow's redis container has the name "ragflow-redis", docker compose doesn't take that into consideration. It seems to track them by project + service name + metadata. So the redis container in both app is messed.

Using '--project-name' is the way to fix the problem, check https://docs.docker.com/compose/how-tos/project-name/ for further information.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.