Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run LabelStudio behind existing proxy #6767

Open
swoKorbi opened this issue Dec 9, 2024 · 1 comment
Open

Run LabelStudio behind existing proxy #6767

swoKorbi opened this issue Dec 9, 2024 · 1 comment

Comments

@swoKorbi
Copy link

swoKorbi commented Dec 9, 2024

Describe the bug
I want to setup LabelStudio with my exisiting Docker stack.
I already do have a Nginx container running that serves all my containers on different subdomains.

My docker-compose file for LablStudio is:

services: 
    labelstudio: 
        image: heartexlabs/label-studio:latest
        container_name: labelstudio
        ports: - "1005:8080" 
        networks: 
          - proxy 
          - labelstudio volumes: 
          - D:\docker\stacks\labelstudio\data\data:/label-studio/data 
          - D:\docker\stacks\labelstudio\data\datasets:/label-studio/datasets 
        environment: 
          - LABEL_STUDIO_HOST=https://my.url
          - LABEL_STUDIO_PORT=8080 
          - LABEL_STUDIO_LOG_LEVEL=INFO 
          - DJANGO_DB=default
          - POSTGRE_NAME=labelstudio 
          - POSTGRE_USER=labelstudio 
          - POSTGRE_PASSWORD=labelstudio 
          - POSTGRE_HOST=labelstudio_postgres 
          - POSTGRE_PORT=5432 
          - LABEL_STUDIO_LOCAL_FILES_SERVING_ENABLED=true 
          - LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT=/label-studio/datasets 
    labelstudio_postgres: 
        image: docker.io/library/postgres:16-alpine
        container_name: labelstudio_postgres
        environment: 
          - POSTGRES_DB=labelstudio
          - POSTGRES_USER=labelstudio 
          - POSTGRES_PASSWORD=labelstudio volumes: 
          - labelstudio-db:/var/lib/postgresql/data
        networks: 
          - labelstudio
    volumes:
        labelstudio-db: 
            external: false 
    networks: 
        proxy: 
            external: false 
            name: proxy
        labelstudio: 
            external: false
            name: labelstudio

My nginx.conf file for LabelStudio is:

events { worker_connections 1024; } 

http { 
  server { 
    listen 80 default_server; 
    server_name _; return 301 https://$host$request_uri; 
  } 
  server { 
    listen 443 ssl;
    server_name my.url;
    client_max_body_size 0; 
    ssl_password_file /var/lib/nginx/ssl_passwords.pass; 
    ssl_certificate /etc/nginx/ssl/vert.crt; 
    ssl_certificate_key /etc/nginx/ssl/vert.key; 

    location / { proxy_pass http://labelstudio:1005/; } }

Unfortunately I do get 502 Bad Gatway when I try to connec tin the browser and 1111 Connection refused to upstream server in my nginx container.

Do i have to set any other environment variables for lablstudio i am missing or do i have to change my nginx conf?

@heidi-humansignal
Copy link
Collaborator

heidi-humansignal commented Dec 11, 2024

Hello,

Would you mind trying this these:

  1. Ensure Both Containers are on the Same Network:
    Make sure that both your Nginx container and the Label Studio container are connected to the same Docker network. Since your Label Studio container is connected to the proxy network, your Nginx container should also be connected to this network.

  2. Update the Nginx Configuration:
    In your nginx.conf, update the proxy_pass directive to use the service name of the Label Studio container instead of localhost. Docker's internal DNS allows containers to reach each other by service name.
    Replace:

    location / { proxy_pass http://localhost:1005/; }

With:

location / { proxy_pass http://labelstudio:8080/; }

This change tells Nginx to forward requests to the labelstudio service on port 8080, which is the internal port that Label Studio listens on.

  1. Connect Nginx to the Docker Network:
    Ensure your Nginx container is connected to the proxy network. In your Docker Compose file, add the Nginx service and connect it to the proxy network:

    services: nginx: image: nginx:latest container_name: nginx volumes: - /path/to/nginx.conf:/etc/nginx/nginx.conf:ro - /path/to/ssl:/etc/nginx/ssl:ro ports: - "80:80" - "443:443" networks: - proxy

Make sure the proxy network is defined under networks:

networks: proxy: external: false name: proxy

  1. Adjust Ports if Necessary:
    Since Nginx is proxying requests to Label Studio internally via the Docker network, you don't need to map port 1005 on the host. You can remove the ports section from your Label Studio service or adjust it if needed.

    services: labelstudio: image: heartexlabs/label-studio:latest container_name: labelstudio # Remove or adjust the ports section # ports: # - "1005:8080" ...

  2. Verify Environment Variables:
    Ensure that the LABEL_STUDIO_HOST environment variable is correctly set. Since you are accessing Label Studio via https://my.url, you can set:

    environment: - LABEL_STUDIO_HOST=https://my.url - LABEL_STUDIO_PORT=8080 ...

  3. Restart Docker Services:
    After making these changes, restart your Docker Compose stack:

    docker-compose down docker-compose up -d

  4. Verify Connectivity:
    You can test connectivity from the Nginx container to the Label Studio container:

    docker exec -it nginx ping labelstudio

Or check if the Label Studio service is accessible:

docker exec -it nginx curl http://labelstudio:8080/

Thank you,
Abu

Comment by Abubakar Saad
Workflow Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants