【问题标题】:File Not Found - Nginx in Docker未找到文件 - Docker 中的 Nginx
【发布时间】:2018-04-17 08:51:09
【问题描述】:

说明

我有一个带有这个的 docker 容器

nginx.conf

server {
    listen 80;
    index index.php index.html;
    root /var/www/public;

    location / {
        try_files $uri /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass app:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

docker-compose.yaml

version: '2'
services:

  # The Application
  app:
    build:
      context: ./
      dockerfile: app.dockerfile
    working_dir: /var/www
    volumes:
      - ./:/var/www
    environment:
      - "DB_PORT=3306"
      - "DB_HOST=database"

  # The Web Server
  web:
    build:
      context: ./
      dockerfile: web.dockerfile
    working_dir: /var/www
    volumes_from:
      - app
    ports:
      - 85:80

  # The Database
  database:
    image: mysql:5.6
    volumes:
      - dbdata:/var/lib/mysql
    environment:
      - "MYSQL_DATABASE=homestead"
      - "MYSQL_USER=homestead"
      - "MYSQL_PASSWORD=secret"
      - "MYSQL_ROOT_PASSWORD=secret"
    ports:
        - "33062:3306"

volumes:
  dbdata:

docker似乎构建并启动成功

docker-compose up -d
docker_app_1 is up-to-date
docker_database_1 is up-to-date
Recreating docker_web_1 ... 
Recreating docker_web_1 ... done

但我一直得到

找不到文件。

如何调试这个?

【问题讨论】:

  • 您介意分享您的 docker-compose 文件吗?
  • @Sergiu :根据要求,我将我的 docker-compose.yaml 包含在帖子中。
  • @kyo 你有什么解决办法吗?我也遇到了类似的错误

标签: php laravel docker nginx docker-compose


【解决方案1】:

使用 docker exec -it xxxxxx bash 启动您的容器

一旦你这样做了,你就会在容器内。现在根据您的 docker-compose 文件检查您的文件是否位于您放置它们的位置。

【讨论】:

  • 什么是 xxxxxx ?是某种 docker id 吗?还是 pid ?
  • 使用“docker ps”或“docker ps -a”会生成一个docker容器列表。查找容器的 ID。 xxxxxx 是容器 ID。 => 'docker exec -it bash'
【解决方案2】:

所有和其他目录设置理想地指向同一个位置。在您的 nginx.conf 中,您有 root /var/www/public;但是在你的 yal 中你使用 /var/www。那可能是你的问题。

至于继续执行的步骤,您可以在启动 docker-compose.yml 文件后使用以下命令检查您的服务实际使用的目录: docker-compose exec yourServiceName sh

将 yourServiceName 替换为您在 yaml 中定义的任何服务。所以 appwebdatabase 在你上面的 yaml 中。该命令将带您进入指定容器的外壳(sh)。您还可以将 sh 替换为其他命令,以对您的容器执行其他操作。

【讨论】:

    猜你喜欢
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 2021-11-16
    • 2021-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-17
    相关资源
    最近更新 更多