Regarding the issue that air does not work when using Docker to build Go air environment

Asked 2 years ago, Updated 2 years ago, 269 views

Operating System Used: Windows 11
Docker:Docker Desktop for Windows

1. Use the following Dockerfile

 FROM Golang: 1.18

ENV TZ/usr/share/zoneinfo/Asia/Tokyo

ENV ROOT=/go/src/app
WORKDIR${ROOT}


ENV GO111 MODULE=on

COPY.
EXPOSE 8080

RUN go install github.com/cosmtrek/air@latest
CMD ["air"]

2. Terminal Log
Terminal Logs

It looks like it's starting up, but if you make changes to the Go file here, it won't hot reload

I would appreciate it if you could tell me how to solve the problem if you know the cause.

windows docker go

2022-11-15 06:08

1 Answers

"Go's air" is a tool that automatically detects source code changes and restarts applications (here Echo).
GitHub-cosmtrek/air:☁ LLive reload for Goapps

On the other hand, Docker features the ability to build images from source code and boot and run from the same state.

In the Dockerfile listed, copy the current source code to the Docker image at the time of the line COPY., and the Docker container is running with this code.
Therefore, when editing the code at hand, the air inside the Docker cannot detect it and does not result in a hot reload.

There are two possible ways to avoid containers or mount development environment directories.


2022-11-15 06:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.