Skip to main content

Static Website in Docker with OpenTofu

One tofu apply serves your static website from nginx in Docker, with checked settings, a health check, seven tests and a clean tofu destroy.

  • OpenTofu
  • Docker provider (kreuzwerker/docker)
  • HTTP provider (hashicorp/http)
  • nginx (alpine image)
  • Docker Desktop

Screenshots

Screenshot 1 of 4: Title card of Static Website in Docker with OpenTofu: the promise, the stack chips and the end of a real tofu apply, with 2 resources added and the url output http://127.0.0.1:8080/.

Title card of Static Website in Docker with OpenTofu: the promise, the stack chips and the end of a real tofu apply, with 2 resources added and the url output http://127.0.0.1:8080/.

One-off price

  • ₹299+ GST, ₹352.82 in total
  • $5
  • Download it from your library as soon as your payment is confirmed.
  • Every later release of this project is included, at no extra cost.
Latest release
1.0.0 · Nov 18, 2026

Overview

The complete source code of an OpenTofu configuration that serves a folder of static files from nginx in Docker on your own computer. Every setting is checked before anything is created, the apply finishes only when nginx answers, a check confirms the site returns 200, and seven tests run without Docker. Tested on macOS with Docker Desktop.

Putting a static site in a container is easy once. Doing it so a wrong setting is caught before anything starts, the command waits until the site really answers, and one command removes everything again takes more care. Static Website in Docker with OpenTofu® is that configuration, tested in real runs on macOS with Docker Desktop.

What it does

  • Serves your site from nginx in Docker. Point it at any folder with an index.html, and every file in it, subfolders included, is copied into an nginx container.
  • One command up, one command down. tofu apply downloads the official nginx:1.31-alpine image and starts the container. tofu destroy removes the container and the image.
  • Private by default. The site listens on 127.0.0.1:8080, so only your computer can open it. One setting opens it to your network.
  • Updates when your files change. Change a file and run tofu apply again: the container is replaced with one that has the new files.

Built so mistakes show up early

  • Every setting is checked first. The container name, the site folder, the port (1024 to 65535), the address and the image are validated before anything is created, each with a clear message.
  • The apply waits for a healthy site. A health check inside the container asks nginx for the home page, and tofu apply finishes only once it answers.
  • A check after every apply. A check block requests the site and warns if it doesn't answer with 200.
  • Seven tests. tofu test covers the defaults, the network option and every input check. The providers are mocked, so the tests need no Docker and create nothing.

Code you can build on

  • Small and readable. Six short .tf files, each with one job: versions, the provider, settings, resources, the check and outputs.
  • Pinned and repeatable. Version constraints for OpenTofu and both providers, and a lock file with checksums for macOS (Apple silicon and Intel), Linux (x86-64 and Arm) and Windows.
  • Ready for Git. A .gitignore that keeps state and plans out, and .gitattributes for consistent line endings.
  • Every setting in one example file. Copy terraform.tfvars.example and change what you need.

What it doesn't include

  • No hosting. It runs the site on your own computer. Putting it on a server or in the cloud is up to you.
  • No HTTPS. nginx serves plain HTTP on the port you choose.
  • No site builder. It serves the files you give it. The sample is a one-page shop.

Run it in four steps

  1. Install OpenTofu 1.13 or newer and start Docker. On a Mac, switch on Docker Desktop's default socket, or set docker_host.
  2. Unzip the download and open a terminal in its folder.
  3. Run tofu init, then tofu apply, and type yes.
  4. Open http://127.0.0.1:8080/ in your browser.

Every step, with screenshots: How to Set Up and Run the Static Website in Docker with OpenTofu (opens in a new tab).

Learn the ideas behind the code in the free OpenTofu Tutorial for Beginners (opens in a new tab).

OpenTofu® is a registered trademark of LF Projects, LLC. Docker is a trademark of Docker, Inc. Other names are trademarks of their respective owners.

Free tutorial series

OpenTofu Tutorial for Beginners

Prefer to learn by building it? This free, step-by-step guide on our blog shows how the project is made.

Read the series (opens in a new tab)

What you get

Everything in the archive, at a glance.

  • Version 1.0.0 of the complete source code: six OpenTofu files, a sample site and a test file
  • Checked settings for the container name, site folder, port, address and nginx image
  • An nginx container with a health check, and an apply that waits until the site answers
  • A check block that confirms the site answers with 200 after every apply
  • Seven tests with mocked providers that run without Docker
  • A lock file with provider checksums for macOS, Linux and Windows
  • An example settings file, a .gitignore and a .gitattributes file
  • A README with the requirements, every setting, the outputs, troubleshooting and clean-up

Built with

The exact runtimes and versions it was built and tested against.

  • OpenTofu1.13.9
  • Docker provider (kreuzwerker/docker)4.7.0
  • HTTP provider (hashicorp/http)3.6.3
  • nginx (alpine image)1.31
  • Docker Desktop4.99.0

What is in the archive

The file tree you get once you unzip it.

static-website-docker-opentofu/

  • site/
  • tests/
  • .gitattributes
  • .gitignore
  • .terraform.lock.hcl
  • README.md
  • checks.tf
  • main.tf
  • outputs.tf
  • providers.tf
  • terraform.tfvars.example
  • variables.tf
  • versions.tf

What it needs from you

The accounts and services it expects to find, so nothing is a surprise.

  • OpenTofu 1.13 or newer, below 2.0
  • Docker: Docker Desktop on macOS or Windows, or Docker Engine on Linux
  • On a Mac, Docker Desktop's default socket switched on, or the Docker address set in docker_host
  • A free port on your computer, 8080 by default
  • Your website's files, with an index.html at the top (a sample site is included)

Releases

Every version so far, newest first.

  1. 1.0.0Latest

    First release of the complete source code.

    • Serves any folder of static files from nginx 1.31 in Docker, on 127.0.0.1:8080 by default.
    • Checks every setting before anything is created, and waits until the site answers.
    • Includes seven tests, a sample site and a lock file for macOS, Linux and Windows.

Source Code Licence

What you may do with it

What you may and may not do with the source code you buy.

Read the full licence
  1. What this licence covers

This licence governs every file included in a product you buy from Dewiride Store: source code, configuration, database scripts, sample data, documentation and any other file in the download. It takes effect when your payment is confirmed and applies to every release of that product that reaches your library. Files that reach your library through an annual updates membership are governed in exactly the same way.

It forms part of the Terms of Sale and Use. Where a product page states different or additional licence terms for that product, those terms prevail for that product. The membership page may likewise state different or additional licence terms for the files a membership carries, and those terms then prevail for those files.

  1. The licence we grant you

We grant you a perpetual, worldwide, non-exclusive, non-transferable licence to use, reproduce, adapt, translate and modify the files, and to include the result in your own work, on the conditions set out below.

Perpetual means it does not expire. Worldwide means it is not limited to any country. Non-exclusive means we license the same product to other customers. Non-transferable means you cannot pass it on to someone else.

The licence is granted to you — either you personally, or the organisation you identified when buying. Everyone working within that organisation may use the files for that organisation’s projects. Nobody outside it may.

  1. What you may do
  • Use and change the files in your own projects, commercial or otherwise, with no limit on the number of projects.
  • Build a product or a service on them and charge your own customers for it.
  • Deploy the result for a client, as part of work you are doing for that client.
  • Distribute the result in compiled, deployed or otherwise non-source form.
  • Keep as many back-up copies as you reasonably need.
  • Study, observe and test how the code works, and obtain the information you need to make it work with your own software.

The last two are yours by law under sections 52(1)(aa) to (ac) of the Indian Copyright Act, 1957, and nothing in this licence is intended to take them away.

  1. What you may not do
  • Resell, sublicense, redistribute or publish the files themselves, in whole or in substantial part, in source form.
  • Include them in a template, starter kit, course, tutorial repository or component library that you sell or give away, where the code is the thing being supplied.
  • Share your account, your download links or your invoices with anyone outside your organisation.
  • Publish the files in a public repository, or in any other place where they can be obtained without buying them.
  • Remove or obscure the copyright and attribution notices in the source files.
  • Use the files to build something whose main purpose is to compete with Dewiride Store as a supplier of the same code.

The distinction that matters is simple: you may sell what you build with the code; you may not sell the code.

  1. Third-party components

Our products depend on open-source libraries, frameworks and services that we did not write. Those remain under their own licences, which we do not and cannot change. Where a product includes or requires such a component, its licence is named in the product’s documentation, and complying with it is your responsibility.

  1. Releases

Every release of a product you own is covered by this same licence and appears in your library at no extra cost. A release you have already downloaded remains licensed to you even if we later stop publishing the product. A release that reached your library through an annual updates membership is licensed to you on these same terms, and stays licensed after the period that carried it has ended.

  1. Ownership

We keep ownership of the files and of the copyright in them. You own whatever you create with them: your changes, your additions and the product you build are yours.

  1. If this licence ends

This licence ends if you materially breach it and do not put the breach right within thirty days of us asking you to in writing. It also ends if your payment is reversed or refunded, because the purchase it depends on no longer stands. Where a membership period is refunded or reversed, the licence ends for the releases that period carried and for nothing else: anything you bought separately, or that another period carried, is unaffected.

If it ends, you must stop using the files and delete the copies you hold. Work you had already delivered to a client before that point may continue in use, so that ending this licence never breaks something your own customer relies on.

  1. No warranty beyond the description

The warranties and limits in section 19 and section 20 of the Terms of Sale and Use apply to this licence as well.

  1. Governing law

This licence is governed by the law of India, and section 24 of the Terms of Sale and Use applies to any dispute about it. If a translation and the English version differ in meaning, the English version governs.