Go projects and docker compose watch

Luke Rogerson
1 min readOct 20, 2023

--

Photo by Gary Ellis on Unsplash

docker compose watch (AKA hot reload) is now available to everyone. It’s a nice tool for automatic updating of running containers upon save.

Something I haven’t seen discussed much on the internet or from Googling is how to use it with a Go project, so I thought I’d document how you can easily use it with yours.

Prerequisites

Make sure you have at least Docker Desktop 4.24 or Docker Compose standalone 2.22.0 installed.

Steps

(I’m assuming you have an existing Go project with a main.go in the root. You may need to adjust this setup some for your specific needs)

  1. Add a Dockerfile for creating an image:
An example Dockerfile

2. Add a docker-compose.yml. Notice the develop block. rebuild will build a new image and replace the running container, useful for compiled languages like Go!

An example docker-compose.yml

3. Run docker compose up --build -d to ensure images are freshly built, then docker compose watch to watch for file changes.

4. Make changes to your Go project and see the changes applied automatically!

Take a look at this GitHub repo for a fuller example!

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Luke Rogerson
Luke Rogerson

Written by Luke Rogerson

Full-stack software engineer. I like to create, teach and learn. www.lukerogerson.me

Responses (2)

Write a response