You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker端口未正常暴露求助——附docker-compose.yml配置

Hey there, let's break down your current docker-compose.yml first, and cover some common pitfalls that might be causing whatever issue you were about to describe (since your question got cut off):

Your Current Docker Compose Configuration

version: '3'
services:
  app:
    build: .
    ports:
      - "8000:8000"
    volumes:
      - .:/srv/redditaurus
    environment:
      - REDDIT_KEY=${REDDIT_KEY}
      - REDDIT_SECRET=${REDDIT_SECRET}
    links:
      - mysql:mysql
  mysql:
    image: mysql
    environment:
      MYSQL_ROOT_PASSWORD: root
    ports:
      - "3306:3306"
    # volumes:
    # - ./mysql:/var/lib/mysql/
  nginx:
    image: nginx
    ports:
      - "80:80"

Key Observations & Fixes for Common Issues

Based on what you've shared, here are some things to check if you're having trouble extending this setup:

  • MySQL Data Persistence: You've commented out the volume mount for MySQL. This means every time you stop/start the MySQL container, all your database data will be lost. Uncomment those lines to persist your database data locally:

    volumes:
      - ./mysql:/var/lib/mysql/
    
  • Nginx Isn't Configured to Proxy to Your App: Right now, the Nginx container is running but has no idea about your app service. If you're trying to access your app via port 80 (instead of 8000), you need to add a custom Nginx config and mount it into the container. For example:

    1. Create a nginx.conf file in your project root:
      server {
        listen 80;
        server_name localhost;
      
        location / {
          proxy_pass http://app:8000;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
        }
      }
      
    2. Update the Nginx service in your docker-compose.yml to mount this config:
      nginx:
        image: nginx
        ports:
          - "80:80"
        volumes:
          - ./nginx.conf:/etc/nginx/conf.d/default.conf
        depends_on:
          - app
      
  • links is Deprecated: While links still works in Compose v3, the modern approach is to use a custom network for service communication. Add a network definition at the bottom of your file and attach all services to it:

    networks:
      app-network:
        driver: bridge
    

    Then add networks: - app-network to each service (app, mysql, nginx).

  • Environment Variables: Make sure you have a .env file in your project root with your actual Reddit API keys, or that you've exported those variables in your shell before running docker-compose up. If not, your app might fail to connect to the Reddit API.

If you can share more details about the specific issue you're facing (like what happens when you try to do X), I can give more targeted advice!

内容的提问来源于stack exchange,提问作者Mansoor Syed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:50:36