gpt4 book ai didi

docker - Jekyll 站点在 docker 容器内运行,但 localhost 为 :4000 is not working on host

转载 作者:行者123 更新时间:2023-12-04 01:41:54 32 4
gpt4 key购买 nike

目录结构:

  • docker-compuse.yml
  • /faq/....所有网站

  • 在根目录中我运行 docker-compose up --build我得到该站点正在运行的输出:
    faq-site_1  | Configuration file: /srv/faq/_config.yml
    faq-site_1 | Source: /srv/faq
    faq-site_1 | Destination: /srv/faq/_site
    faq-site_1 | Incremental build: disabled. Enable with --incremental
    faq-site_1 | Generating...
    faq-site_1 | done in 1.37 seconds.
    faq-site_1 | Auto-regeneration: enabled for '/srv/faq'
    faq-site_1 | LiveReload address: http://127.0.0.1:35729
    faq-site_1 | Server address: http://127.0.0.1:4000/faq/
    faq-site_1 | Server running... press ctrl-c to stop.

    我使用 docker exec -it c94ad3af91c9 bash SSH 到容器并执行 curl localhost:4000 .得到了 HTML 的预期结果。

    我尝试在 http://127.0.0.1:4000 上运行该站点从主机和 Chrome 失败并显示“ERR_EMPTY_RESPONSE”。

    我已将 jekyll 配置为在 /faq 的子目录上运行.尝试访问
  • http://127.0.0.1:4000
  • http://127.0.0.1:4000/faq
  • http://127.0.0.1:4000/faq/

  • 没有任何效果。我总是从 chrome 得到这个:

    enter image description here

    Dockerfile:
    FROM ubuntu:16.04

    RUN apt-get update
    RUN apt-get install -y --no-install-recommends apt-utils
    RUN apt-get install -y ruby ruby-dev build-essential
    RUN gem install jekyll bundler
    RUN gem install jekyll-feed
    RUN gem install jekyll-paginate
    RUN gem install minima

    RUN bundle -v
    RUN gem -v
    RUN jekyll -v

    COPY ./ /srv/faq
    WORKDIR /srv/faq
    CMD ["bundle", "exec", "jekyll", "serve", "--livereload"]

    docker -compose.yml:
    version: '3'

    services:
    faq-site:
    build: ./faq
    volumes:
    - ./faq:/srv/faq
    ports:
    - "4000:4000"
    - "35729:35729"

    最佳答案

    尝试绑定(bind) 0.0.0.0 .然后您的网站可以从外部 ip 访问。

    CMD ["bundle", "exec", "jekyll", "serve", "--livereload", "--host", "0.0.0.0"]

    关于docker - Jekyll 站点在 docker 容器内运行,但 localhost 为 :4000 is not working on host,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51404768/

    32 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com