Docker 容器发送空响应

Docker container sending empty responses

希望有人能告诉我我缺少什么?这是一个使用 webrick 的 ruby 应用程序,我正在尝试将该应用程序容器化。 运行 Mac OSX 10.12.3 塞拉利昂。这是我的 Dockerfile

FROM ruby:2.4.0-alpine
RUN apk add --no-cache gcc musl-dev libstdc++ g++ make
RUN gem install jekyll bundler redcarpet
RUN mkdir -p /usr/app/jekyll
COPY . /usr/app/jekyll
WORKDIR /usr/app/jekyll
EXPOSE 4000:4000
CMD ["jekyll", "serve"]

图像的构建方式如下

docker build -t chb0docker/cheat .

如果我 运行 服务直接在主机上,它 运行 没问题

Violas-MacBook-Pro:progfun-wiki cbongiorno$ jekyll serve &
[1] 49286
Violas-MacBook-Pro:progfun-wiki cbongiorno$ Configuration file: /Users/cbongiorno/development/progfun-wiki/_config.yml
Configuration file: /Users/cbongiorno/development/progfun-wiki/_config.yml
            Source: /Users/cbongiorno/development/progfun-wiki
       Destination: /Users/cbongiorno/development/progfun-wiki/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
                    done in 0.409 seconds.
 Auto-regeneration: enabled for '/Users/cbongiorno/development/progfun-wiki'
Configuration file: /Users/cbongiorno/development/progfun-wiki/_config.yml
    Server address: http://127.0.0.1:4000/
  Server running... press ctrl-c to stop.

验证服务器已启动:

Violas-MacBook-Pro:progfun-wiki cbongiorno$ curl localhost:4000 2> /dev/null | wc -l
      40

现在 运行 它在 docker:

Violas-MacBook-Pro:progfun-wiki cbongiorno$ fg
jekyll serve
^C
Violas-MacBook-Pro:progfun-wiki cbongiorno$ docker run -d --name jekyll -p 4000:4000 chb0docker/cheat 
e766e4acb007033583885b1a3c52dc3c2dc51c6929c8466f3a4ff958f76ebc5f

验证进程

Violas-MacBook-Pro:progfun-wiki cbongiorno$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                    NAMES
e766e4acb007        chb0docker/cheat    "jekyll serve"      19 minutes ago      Up 32 seconds       0.0.0.0:4000->4000/tcp   jekyll
Violas-MacBook-Pro:progfun-wiki cbongiorno$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' jekyll
172.17.0.3
Violas-MacBook-Pro:progfun-wiki cbongiorno$ docker logs jekyll
Configuration file: /usr/app/jekyll/_config.yml
Configuration file: /usr/app/jekyll/_config.yml
            Source: /usr/app/jekyll
       Destination: /usr/app/jekyll/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
                    done in 0.329 seconds.
 Auto-regeneration: enabled for '/usr/app/jekyll'
Configuration file: /usr/app/jekyll/_config.yml
    Server address: http://127.0.0.1:4000/
  Server running... press ctrl-c to stop.

现在尝试获取一些数据

Violas-MacBook-Pro:progfun-wiki cbongiorno$ curl localhost:4000 2> /dev/null | wc -l
       0
Violas-MacBook-Pro:progfun-wiki cbongiorno$ curl 172.17.0.3:4000 2> /dev/null | wc -l
       0
Violas-MacBook-Pro:progfun-wiki cbongiorno$ curl 0.0.0.0:4000 2> /dev/null | wc -l
       0

但是,如果我们执行上面的 GET(使用 wget 而不是 curl 因为它没有安装在这个容器上)我们可以看到容器里的一切都很好

 docker exec -it jekyll /usr/bin/wget -q -O - localhost:4000 | wc -l
      40

这是应用程序问题吗?

看起来 Jekyll 正在绑定到本地主机。要么像这样启动容器:

docker run -d --name jekyll -p 127.0.0.1:4000:4000

或者让 Jekyll 绑定到 0.0.0.0:

CMD ["jekyll", "serve", "--host", "0.0.0.0"]