How do I live reload in a Linux Docker container?

I cannot load my website when implementing live reloading in Jekyll with my docker container. What I wanted to do was toggle between two different commands in my compose file.

One configuration is for live reloading in the container.

command: jekyll serve --watch --force_polling

The other (which is commented out) is to live reload and display unpublished blogs with the Front Matter Published property set to False. I wanted to switch between them.

But all they do is prevent the website from loading at localhost:4000 when I run docker compose up -d

I have removed the Jekyll cache files, reinstalled the gem files with bundle install and compiled it successfully with the dependencies installed on my WSL2 Ubuntu instance.

If it helps here are my docker files.


# Use the official Ruby image
FROM ruby:3.0

# Install Jekyll and Bundler
RUN gem install jekyll bundler

# Set the working directory to /app

# Copy your Jekyll project files into the container
COPY . .

# Install dependencies
RUN bundle install

# Expose port 4000 (Jekyll default)

# Command to run Jekyll
CMD ["jekyll", "serve", "--host", ""]

Here’s my docker-compose.yml file:

version: "3.9"
      context: .
      dockerfile: Dockerfile
      - "4000:4000"
      - .:/app

command: jekyll serve --watch --force_polling
#command: jekyll servey --unpublished --watch --force_polling

I don’t see watch as a jekyll command, where did you see that?

The command is --livereload or -l

also your second command has a spelling issue.

Along with @rdyar’s statements, I see some potential challenges here. For example, I do not see you running bundle install or bundle update to install any packages before running your Jekyll project.

I successfully run Docker on my computer, but I use Dev Containers, which (in my opinion) are easier to develop with. Even if you do not want to use Dev Containers, you will learn the steps to run Docker containers on your computer with this video I created:

Hi people,

Sorry for the slow response. I already know who you are @BillRaymond, and I have to say your video convinced me to stop using WSL 2 and transition to Dev Containers since there’s no generic Linux tool I use in WSL 2 anyway. Thanks for your video, I know it was a colossal amount of effort!

@rdyar thanks for pointing that embarrassing mistake out. I saw --watch used in a tutorial. As for --livereload or -l the reason I used --force_polling instead is that I heard it is an alternative that works better with docker volumes. I will try both to see how I go thanks.

Hi @jords287, glad you got it all sorted out and thank you for the kind words!