Hoping someone can tell me what I am missing? This is a ruby app using webrick and I am trying to containerize the app. Running on Mac OSX 10.12.3 Sierra. Here is my 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"]
Here is how the image is built
docker build -t chb0docker/cheat .
if I run the service directly on the host, it runs fine
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.
verify the server is up:
Violas-MacBook-Pro:progfun-wiki cbongiorno$ curl localhost:4000 2> /dev/null | wc -l
      40
now run it in 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
verify the process
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.
now try and get some data
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
but, if we execute the above GET (with wget instead of curl because it's not installed on this container) we can see all is well inside the container
 docker exec -it jekyll /usr/bin/wget -q -O - localhost:4000 | wc -l
      40
Is this an app issue?
Looks like Jekyll is binding to localhost. Either start the container like this:
docker run -d --name jekyll -p 127.0.0.1:4000:4000
Or have Jekyll bind to 0.0.0.0:
CMD ["jekyll", "serve", "--host", "0.0.0.0"]
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With