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

Docker部署Invoice Ninja遇阻求助:APP_KEY生成报错与本地访问异常问题

Troubleshooting Your Local Invoice Ninja Docker Deployment

Hey Luis, let's work through each of your issues to get Invoice Ninja running smoothly on your local machine:

1. Is the SQL Error When Generating APP_KEY Normal?

That error is expected if you're running the key generation command on your local machine instead of inside the Docker container. Here's why:

  • The php artisan key:generate command tries to connect to the database to validate the environment, but your local machine doesn't have the MySQL instance running (it’s isolated inside the Docker db container).
  • This isn’t a critical failure, but it’s not the correct way to generate the key. The proper approach is to run the command within the web container where it can access the database service via Docker’s internal network.

2. Fixing Page Not Found & 502 Bad Gateway Errors

These issues stem from misconfigured environment variables, Docker network settings, or host file mappings. Let’s resolve them step by step:

Step 1: Generate APP_KEY Correctly

  1. First, start just the database container to ensure it’s fully initialized:
    docker-compose up -d db
    
  2. Wait 30-60 seconds for MySQL to boot, then enter the web container:
    docker-compose exec web bash
    
  3. Inside the container, run the key generation command (this will work because the container can reach the db service):
    php artisan key:generate
    
  4. Exit the container with exit once done.

Step 2: Verify Critical .env Configurations

Open your .env file and double-check these key settings:

  • DB_HOST=db (not localhost—Docker Compose uses service names for internal container communication)
  • Ensure DB_DATABASE, DB_USERNAME, and DB_PASSWORD match the environment variables set for the db service in your docker-compose.yml (default values are usually ninja, ninja, ninja)
  • Keep APP_URL=http://in5.test:8000 as you configured it.

Step 3: Fix Host File & Docker Compose Settings

  • Host File: Edit your local hosts file (Linux/macOS: /etc/hosts; Windows: C:\Windows\System32\drivers\etc\hosts) and add this line:
    127.0.0.1 in5.test
    
  • Docker Compose Ports: Confirm your web service has the correct port mapping to expose the container to your local machine:
    ports:
      - "8000:80"
    
  • Extra Hosts: The extra_hosts configuration lets the container access services on your local machine. If you don’t need this functionality, you can remove the line entirely—it doesn’t affect your ability to access the container from your host.

Step 4: Reset & Restart Services

  1. Stop all running containers to clear stale state:
    docker-compose down
    
  2. Restart services in detached mode:
    docker-compose up -d
    
  3. Verify both db and web containers are running:
    docker-compose ps
    
  4. If errors persist, check the web container logs for detailed troubleshooting info:
    docker-compose logs web
    

Step 5: Fix File Permissions

Ensure local mounted directories have the correct ownership for the container to access files. Run this from your repo directory:

chown -R 1500:1500 ./docker/app/public

The 1500:1500 UID/GID matches the user used inside the Invoice Ninja Docker container.

Final Access Test

Once all services are up, open your browser and navigate to http://in5.test:8000—you should see the Invoice Ninja setup page.

内容的提问来源于stack exchange,提问作者Luis Enrique

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.29 04:52:47