You have the source code of the Catalogue Website in Docker with OpenTofu®. This guide takes it from the zip file to a catalogue website running in Docker on your own computer, then shows how to replace the sample list with your own items and how to remove everything again.
By the end, nginx serves your catalogue at http://127.0.0.1:8080/, with an “in stock” or “sold out” label after every item, and one command removes it.
Every command and output on this page is real, run on OpenTofu 1.13 with Docker Desktop on macOS. The OpenTofu commands are the same in Windows PowerShell and on Linux.
Cost: free to run. Everything runs on your own computer. Docker Desktop is free for personal use, education, non-commercial open source projects and small businesses; larger organizations need a paid subscription (Docker Desktop license agreement (opens in a new tab)).
Get the Source Code
Get the complete source code of Catalogue Website in Docker with OpenTofu on Dewiride Store → (opens in a new tab)
The archive holds everything this guide sets up and runs.
Prerequisites
- OpenTofu 1.13 or newer: How to Install OpenTofu on macOS, or the OpenTofu installation docs (opens in a new tab) for Windows and Linux.
- Docker Desktop (opens in a new tab), running. On Linux, Docker Engine (opens in a new tab) works too.
- On a Mac, Docker Desktop’s default socket switched on: How to Enable /var/run/docker.sock in Docker Desktop for Mac.
- The zip you downloaded,
catalogue-website-docker-opentofu-1.0.0.zip.
Step 1: Unzip the Source Code
Open a terminal in the folder that holds the zip, such as Downloads, and unzip it. On Windows, you can also right-click the zip in File Explorer and choose Extract All.
unzip catalogue-website-docker-opentofu-1.0.0.zip
It creates a folder named catalogue-website-docker-opentofu. Go into it:
cd catalogue-website-docker-opentofu
The folder holds the OpenTofu files (.tf), a templates folder with the page template and its style sheet, an example settings file and a README that lists every setting.
Step 2: Download the Providers with tofu init
tofu init downloads the two providers the code uses, at the exact versions recorded in its lock file (what tofu init does):
tofu init
Initializing the backend...
Initializing provider plugins...
- Reusing previous version of kreuzwerker/docker from the dependency lock file
- Reusing previous version of hashicorp/http from the dependency lock file
- Installing kreuzwerker/docker v4.7.0...
- Installing hashicorp/http v3.6.3...
- Installed hashicorp/http v3.6.3 (signed, key ID 0C0AF313E5FD9F80)
- Installed kreuzwerker/docker v4.7.0 (signed, key ID 0DCE698927DAF8EC)
Providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://opentofu.org/docs/cli/plugins/signing/
OpenTofu has been successfully initialized!
Step 3: Start the Website with tofu apply
Run tofu apply. It shows its plan, an nginx image and a container, and asks you to confirm. Type yes:
tofu apply
Plan: 2 to add, 0 to change, 0 to destroy.
docker_image.nginx: Creating...
docker_image.nginx: Creation complete after 0s [id=sha256:7f2d42982b61384c4808f31f7215d19db7ceed3056dc680b84be5790b0cb4c39nginx:1.31-alpine]
docker_container.site: Creating...
docker_container.site: Creation complete after 6s [id=bfb0625eaadc3e53453d3cedfa4bc860fb7cd5c6cf05170dde4b56815cee8674]
data.http.home: Reading...
data.http.home: Read complete after 0s [id=http://127.0.0.1:8080/]
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
Outputs:
available_items = [
"The Paper Lantern Café",
"A Map of Quiet Places",
"Salt and Starlight",
]
container_name = "catalogue-website"
image = "nginx@sha256:7fc0fb4af7bf006aeb31aea88069976060f8f0a0a86b667126742cc17f4e31ae"
item_names = tolist([
"The Paper Lantern Café",
"A Map of Quiet Places",
"The Clockmaker's Garden",
"Salt and Starlight",
])
url = "http://127.0.0.1:8080/"
tofu apply finishes only when nginx answers inside the container, and a check then confirms that the website answers too. The outputs list every item and the ones that are available.
Step 4: Open the Website
Open http://127.0.0.1:8080/ in your browser. The sample catalogue is a small bookshop:

Step 5: Make the Catalogue Yours
Your own items go in a file named terraform.tfvars, which OpenTofu reads by itself (.tfvars vs .auto.tfvars). Start from the example file that comes with the code. On Windows, copy it in File Explorer and name the copy terraform.tfvars:
cp terraform.tfvars.example terraform.tfvars
Open it in any text editor. The example is a small bakery:
site_title = "Corner Bakery"
intro = "Baked fresh every morning."
items = [
{ name = "Sourdough loaf", detail = "Slow-rised for 24 hours" },
{ name = "Lemon tart", detail = "With a crisp butter base" },
{ name = "Plum cake", detail = "Back in autumn", available = false },
]
available_label = "available"
unavailable_label = "sold out"
site_titleis the heading, andintrothe line under it. An emptyintroshows no line.- Each item in
itemsneeds aname.detailadds a second line, andavailable = falsemarks it as sold out. available_labelandunavailable_labelare the two labels.
Change the items to your own, then apply again and type yes. The new page replaces the container (update in place vs replace):
tofu apply
Plan: 1 to add, 0 to change, 1 to destroy.
Outputs:
available_items = [
"Sourdough loaf",
"Lemon tart",
]
container_name = "catalogue-website"
image = "nginx@sha256:7fc0fb4af7bf006aeb31aea88069976060f8f0a0a86b667126742cc17f4e31ae"
item_names = tolist([
"Sourdough loaf",
"Lemon tart",
"Plum cake",
])
url = "http://127.0.0.1:8080/"
Refresh the browser:

OpenTofu checks every setting first. Two items with the same name, an empty name or a port outside 1024 to 65535 stop the apply with a message that says which setting is wrong.
Step 6: Read the Lists with tofu output
The outputs stay available after the apply. To print just the available items (tofu output -raw and -json shows more):
tofu output available_items
[
"Sourdough loaf",
"Lemon tart",
]
Clean Up
Run tofu destroy and type yes. It removes the container and the nginx image (tofu destroy):
tofu destroy
Plan: 0 to add, 0 to change, 2 to destroy.
Destroy complete! Resources: 2 destroyed.
Your terraform.tfvars stays in the folder, so the next tofu apply builds the same catalogue again. To keep the nginx image after a destroy, set keep_image = true.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Editing terraform.tfvars.example instead of a copy | OpenTofu doesn’t read the example file, so the sample books stay. | Copy it to terraform.tfvars and edit the copy. |
| Forgetting the comma between two items | OpenTofu stops with a syntax error and the line number. | End every item with },, as in the example. |
Leaving out available | The item counts as available. | Add available = false to the items that are sold out. |
Troubleshooting
| Problem | Why | Fix |
|---|---|---|
Cannot connect to the Docker daemon | Docker isn’t running, or on a Mac the default socket is switched off. | Start Docker Desktop. On a Mac, switch on the default socket (Prerequisites). |
port is already allocated or address already in use | Another program already uses port 8080. | Add host_port = 8081 to terraform.tfvars and open the address the url output prints. |
Item names must be unique (ignoring upper and lower case). | Two items have the same name. | Rename one of them. |
| The page still shows the old list | The browser shows a cached copy. | Reload the page without the cache. |
FAQ
Can I change how the page looks?
Yes. The page is templates/index.html.tftpl and its style is templates/style.css. Edit them and run tofu apply. The page is filled in with OpenTofu’s templatefile function (opens in a new tab).
Is the website open to other computers?
No. It listens on 127.0.0.1, so only your computer can open it. Set bind_address = "0.0.0.0" to open it to your network.
Can a name contain & or <?
Yes. The code escapes &, < and > before it writes the page, so Tea & Biscuits shows as written.
Conclusion
You unzipped the code, started the catalogue with tofu init and tofu apply, replaced the sample with your own items in terraform.tfvars, and removed it all with tofu destroy. To learn how the code builds the list, read Part 5 of the OpenTofu Tutorial.
Additional Resources
- OpenTofu Tutorial — Part 5: Locals, Expressions and tofu console
- OpenTofu Tutorial for Beginners
- OpenTofu docs: templatefile function (opens in a new tab)
- Docker provider (kreuzwerker/docker) on the OpenTofu Registry (opens in a new tab)
- The official nginx image on Docker Hub (opens in a new tab)
OpenTofu® is a registered trademark of LF Projects, LLC. Docker is a trademark of Docker, Inc. Other names mentioned are trademarks of their respective owners. JD Bots isn’t affiliated with or endorsed by the OpenTofu project.
0 comments