DOCKER - 5 6 Exercice Bind Mounts

Bind mounts shine for local development and testing. Because they map a host directory straight into the container, you can edit files in your favourite editor and the running process inside the container picks up the changes immediately. In this exercise we'll use a static site generator called Jekyll. Don't worry — this is not a web-dev tutorial, we'll only edit one line of Markdown. The goal is to internalise the idea of host files mounted inside a container, modified on the host, instantly visible inside.

A live Jekyll preview backed by a bind mount

Jekyll takes Markdown files (essentially plain text) and renders them into a static HTML website. It's what GitHub Pages uses under the hood. Normally you'd have to install Ruby, Bundler, a watcher and a tiny web server on your machine. With Docker, someone packaged the whole stack in a single image — you don't install any of it on the host.

Open the sample bind-mount directory in the course repo and run:

docker container run -p 80:4000 -v $(pwd):/site bretfisher/jekyll-serve

This publishes container port 4000 on host port 80 and bind-mounts the current directory into /site inside the container. Open localhost in a browser — you'll see the default site generated by Jekyll.

  • Edit any post under the _posts/ directory in your editor of choice (VS Code, Vim, anything)
  • Save — Jekyll's watcher detects the change and rebuilds the site automatically
  • Refresh your browser to see the new content
  • Run docker container logs <id> in another tab to see Jekyll announce each file change and rebuild

That's the full bind-mount story: source code lives on the host, the tooling lives in the container, and the loop between edit and preview is as fast as a normal local dev setup — without polluting your machine. If you're stuck, the next lesson walks through this exercise live.

Summary

Bind Mounts are essential for local development, allowing you to mount directories from your host machine into Docker containers and see file changes reflected immediately. This exercise demonstrates a practical workflow using Jekyll, a static site generator, to build HTML websites from markdown files while the containerized tools automatically rebuild the site as you edit files locally. By using Docker with Bind Mounts, developers eliminate the need to install language-specific tools, web servers, and file watchers directly on their machine.

Key points

  • Bind Mounts enable seamless file sharing between host and container, mapping host directories into container paths using docker run with the -v flag
  • Files edited on the host machine are automatically detected by the container, triggering immediate updates and rebuilds without manual intervention
  • Jekyll, the static site generator used in this example, converts plain text markdown into HTML websites—the same tool GitHub Pages uses
  • Docker eliminates dependency hell by packaging all required tools (interpreters, servers, file watchers) inside a single container, removing OS-specific configuration headaches
  • Real-time file synchronization through Bind Mounts streamlines the development workflow, allowing you to use your preferred local editor while the container handles compilation and serving

FAQ

What are Bind Mounts and why are they useful for development?

Bind Mounts allow you to mount a directory from your host machine into a running Docker container. They are particularly useful for development because you can edit files on your host using your preferred editor, while containerized tools (like Jekyll) automatically detect changes and rebuild your application in real-time.

How do you mount a host directory into a Docker container?

Use the docker run command with the -v flag to map the host directory to a container path. For example: docker run -v $(pwd):/site jekyll-image maps your current directory into the container's /site directory, allowing the container to access and process those files.

Why is Jekyll used as the example for Bind Mounts?

Jekyll is a static site generator that converts markdown files into HTML websites. It's a simple, practical example that demonstrates how Bind Mounts work in real development scenarios. Additionally, Jekyll is the same tool GitHub Pages uses, making this skill directly applicable to web developers building blogs and documentation sites.