Can't access site on localhost:4000

Hi all, new to the forum and to Jekyll.

I am running Jekyll in a Docker container on Ubuntu 22.04 LTS.

Here are my logs:

fatal: not a git repository (or any parent up to mount point /srv)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
fatal: not a git repository (or any parent up to mount point /srv)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
logger was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.5.0.
You can add logger to your Gemfile or gemspec to silence this warning.
csv was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.4.0.
You can add csv to your Gemfile or gemspec to silence this warning.
/usr/local/lib/ruby/3.3.0/json/common.rb:3: warning: ostruct was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.5.0.
You can add ostruct to your Gemfile or gemspec to silence this warning.
/usr/local/bundle/gems/safe_yaml-1.0.5/lib/safe_yaml/load.rb:22: warning: base64 was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.4.0.
You can add base64 to your Gemfile or gemspec to silence this warning.
/usr/local/bundle/gems/liquid-4.0.4/lib/liquid.rb:72: warning: bigdecimal was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.4.0.
You can add bigdecimal to your Gemfile or gemspec to silence this warning.
Configuration file: /srv/jekyll/_config.yml
  Jekyll Spaceship: πŸš€ Jekyll-Spaceship 0.10.2
  Jekyll Spaceship: πŸŽ‰ A Jekyll plugin to provide powerful supports.
  Jekyll Spaceship: πŸ‘‰ https://github.com/jeffreytse/jekyll-spaceship
  Jekyll Spaceship: πŸ—‚  use table-processor
  Jekyll Spaceship: πŸ—‚  use mathjax-processor
  Jekyll Spaceship: πŸ—‚  use plantuml-processor
  Jekyll Spaceship: πŸ—‚  use mermaid-processor
  Jekyll Spaceship: πŸ—‚  use polyfill-processor
  Jekyll Spaceship: πŸ—‚  use media-processor
  Jekyll Spaceship: πŸ—‚  use emoji-processor
  Jekyll Spaceship: πŸ—‚  use element-processor
            Source: /srv/jekyll
       Destination: /srv/jekyll/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
       Jekyll Feed: Generating feed for posts
  Jekyll Spaceship: [MathjaxProcessor] _posts/2015-01-01-welcome-to-jekyll.md
  Jekyll Spaceship: [TableProcessor] _posts/2015-02-28-test-markdown.md
  Jekyll Spaceship: [EmojiProcessor] _posts/2015-02-28-test-markdown.md
  Jekyll Spaceship: [PolyfillProcessor] _posts/2016-01-01-another-test-markdown.md
  Jekyll Spaceship: [PlantumlProcessor] _posts/2016-01-01-another-test-markdown.md
  Jekyll Spaceship: [MermaidProcessor] _posts/2016-01-01-another-test-markdown.md
  Jekyll Spaceship: [TableProcessor] _posts/2016-01-01-another-test-markdown.md
  Jekyll Spaceship: [MathjaxProcessor] _posts/2016-01-01-another-test-markdown.md
  Jekyll Spaceship: [MediaProcessor] _posts/2016-01-01-another-test-markdown.md
  Jekyll Spaceship: [EmojiProcessor] _posts/2016-01-01-another-test-markdown.md
  Jekyll Spaceship: [TableProcessor] _posts/2017-05-20-this-post-demonstrates-post-content-styles.md
  Jekyll Spaceship: [TableProcessor] _posts/2017-06-10-quick-mardown-example.md
  Jekyll Spaceship: [MathjaxProcessor] _posts/2017-06-10-quick-mardown-example.md
  Jekyll Spaceship: [PlantumlProcessor] _posts/2017-12-04-plantuml-example.md
  Jekyll Spaceship: [MermaidProcessor] _posts/2017-12-08-mermaid-example.md
  Jekyll Spaceship: [TableProcessor] _posts/2017-12-15-table-example.md
  Jekyll Spaceship: [MathjaxProcessor] _posts/2017-12-15-table-example.md
  Jekyll Spaceship: [MediaProcessor] _posts/2017-12-18-video-example.md
  Jekyll Spaceship: [EmojiProcessor] about.html
  Jekyll Spaceship: [MathjaxProcessor] index.html
                    done in 1.32 seconds.
 Auto-regeneration: enabled for '/srv/jekyll'
    Server address: http://0.0.0.0:4000/
  Server running... press ctrl-c to stop.

Accessing localhost:4000 in Firefox tells me that my browser cannot establish a connection.

Typing in sudo lsof -i :4000 doesn’t bring up anything else on that port.

I can find the IP address of my container, and putting in :4000 gives me an error that my request has timed out.

I can grab the contents of an HTML file and display them in the terminal, so something can see them, it’s just not serving them.

Could you show the Docker command? In particular the -p or --publish flag, which would control how container ports are exposed.

Have you tried to point your browser to http://container_ip/ without the :4000 port?

Thanks for replies, both, sorry for the wait.

docker-compose.yaml looks like this:

  jekyll:
    container_name: $NAME_jekyll
    build:
      context: .
      dockerfile: jekyll.Dockerfile
    ports:
      - "4000:4000"
    volumes:
      - ./srv:/srv/jekyll
    stdin_open: true
    tty: true
    command: /bin/bash

dockerfile looks like this:


FROM ruby:3.3.5-bookworm

RUN <<EOF
    apt-get update
    apt-get upgrade -y
    apt-get install -y --no-install-recommends \
        nano
    apt-get clean
    rm -rf /var/lib/apt/lists/*
EOF

RUN gem install jekyll -v 4.3.4 && gem install bundler

WORKDIR /srv/jekyll

EXPOSE 4000

and to run it all I use a script that does this:


docker compose build --no-cache jekyll
docker compose run jekyll bash

By default the docker compose run command does not setup the networking, so you’d need to add --service-ports. For example (tested):

$ docker compose run --service-ports jekyll bash
root@b876583518e4:/srv/jekyll# jekyll serve -H 0.0.0.0

This fixed it for me. Thank you so much!

1 Like