How to setup with docker inside corporate network? #5360

Closed
opened 2026-02-21 18:10:36 -05:00 by yindo · 1 comment
Owner

Originally created by @shenhai-ran on GitHub (Sep 3, 2024).

Self Checks

  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Provide a description of requested docs changes

Hello,

I am using Dify within my company network, and I am trying to set OpenAI model provide. The problem is that, I need to use self-signed certificate form openai client in python. (http_client=httpx.Client(verfity=...))

How do I set it up using docker deployment?

Thanks

Originally created by @shenhai-ran on GitHub (Sep 3, 2024). ### Self Checks - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Provide a description of requested docs changes Hello, I am using Dify within my company network, and I am trying to set OpenAI model provide. The problem is that, I need to use self-signed certificate form openai client in python. (`http_client=httpx.Client(verfity=...)`) How do I set it up using docker deployment? Thanks
yindo closed this issue 2026-02-21 18:10:36 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 3, 2024):

I found some similar discussions and issues that might be relevant to your question:

  1. Connection error when setting up model provider (open) [1].
  2. How to configure SSL when starting with local source code (open) [2].

To set up Dify with Docker inside a corporate network using a self-signed certificate for the OpenAI client in Python, follow these steps:

  1. Prerequisites: Ensure Docker and Docker Compose are installed on your system.

  2. Environment Setup:

    • Navigate to the docker directory.
    • Copy the .env.example file to a new file named .env by running:
      cp .env.example .env
      
    • Customize the .env file as needed. Refer to the .env.example file for detailed configuration options.
  3. Running the Services:

    • Execute the following command from the docker directory to start the services:
      docker compose up
      
  4. SSL Certificate Setup:

    • Refer to docker/certbot/README.md to set up SSL certificates using Certbot. Since you are using a self-signed certificate, you will need to generate it manually and configure it in the Certbot container.
  5. Configuring the OpenAI Client in Python:

    • When using a self-signed certificate, you need to configure the OpenAI client to trust this certificate. Here is an example of how to do this in Python:

      import openai
      import ssl
      
      # Path to your self-signed certificate
      self_signed_cert_path = "/path/to/your/self-signed-cert.pem"
      
      # Create an SSL context that uses the self-signed certificate
      ssl_context = ssl.create_default_context(cafile=self_signed_cert_path)
      
      # Configure the OpenAI client to use this SSL context
      openai.api_key = "your-openai-api-key"
      openai.api_base = "https://your-dify-instance-url"
      openai.api_client = openai.OpenAIClient(ssl_context=ssl_context)
      
      # Example API call
      response = openai.Completion.create(
          engine="davinci",
          prompt="Hello, world!",
          max_tokens=5
      )
      print(response.choices[0].text.strip())
      

By following these steps, you should be able to set up Dify with Docker inside a corporate network using a self-signed certificate for the OpenAI client in Python [3].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Sep 3, 2024): <!-- Answer --> I found some similar discussions and issues that might be relevant to your question: 1. [Connection error when setting up model provider](https://github.com/langgenius/dify/discussions/7839) (open) <sup>[[1]](https://github.com/langgenius/dify/discussions/7839)</sup>. 2. [How to configure SSL when starting with local source code](https://github.com/langgenius/dify/discussions/7541) (open) <sup>[[2]](https://github.com/langgenius/dify/discussions/7541)</sup>. To set up Dify with Docker inside a corporate network using a self-signed certificate for the OpenAI client in Python, follow these steps: 1. **Prerequisites**: Ensure Docker and Docker Compose are installed on your system. 2. **Environment Setup**: - Navigate to the `docker` directory. - Copy the `.env.example` file to a new file named `.env` by running: ```sh cp .env.example .env ``` - Customize the `.env` file as needed. Refer to the `.env.example` file for detailed configuration options. 3. **Running the Services**: - Execute the following command from the `docker` directory to start the services: ```sh docker compose up ``` 4. **SSL Certificate Setup**: - Refer to `docker/certbot/README.md` to set up SSL certificates using Certbot. Since you are using a self-signed certificate, you will need to generate it manually and configure it in the Certbot container. 5. **Configuring the OpenAI Client in Python**: - When using a self-signed certificate, you need to configure the OpenAI client to trust this certificate. Here is an example of how to do this in Python: ```python import openai import ssl # Path to your self-signed certificate self_signed_cert_path = "/path/to/your/self-signed-cert.pem" # Create an SSL context that uses the self-signed certificate ssl_context = ssl.create_default_context(cafile=self_signed_cert_path) # Configure the OpenAI client to use this SSL context openai.api_key = "your-openai-api-key" openai.api_base = "https://your-dify-instance-url" openai.api_client = openai.OpenAIClient(ssl_context=ssl_context) # Example API call response = openai.Completion.create( engine="davinci", prompt="Hello, world!", max_tokens=5 ) print(response.choices[0].text.strip()) ``` By following these steps, you should be able to set up Dify with Docker inside a corporate network using a self-signed certificate for the OpenAI client in Python <sup>[[3]](https://github.com/langgenius/dify/blob/main/docker/README.md)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5360