air
air copied to clipboard
air started but NOT reloading

It seems to be working, but there's no rebuilding after I change the code.
Dockerfile:
FROM golang:alpine
RUN apk add --no-cache git
WORKDIR /app
COPY go.* .
COPY *air.toml .
RUN go mod download
COPY . .
RUN go install github.com/cosmtrek/air@latest
CMD ["air", "-c", ".air.toml"]
docker-copose.yml
services:
api:
build: .
ports:
- "3000:3000"
depends_on:
- mongo
volumes:
- .:/app
restart: on-failure
environment:
- MONGO_URI=mongodb://admin:password@mongo:27017/test?authSource=admin
mongo:
image: mongo
restart: on-failure
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: password
ports:
- "27017:27017"
volumes:
- mongo:/data/db
- mongo:/data/configdb
volumes:
mongo:
I'm using M1 macbook, just wondering if it's an ARM/AMD thing.
I am also experiencing this... on Intel.. I wonder if related to a new version of Docker or something? Maybe fsnotify for some particular reason/stack not working with mounted volumes? Will continue looking but thought I'd post here to show support. Works fine locally, without Docker.
EDIT: Seems potentially related from mounted volumes on Docker for Windows/WSL not firing the necessary I/O events.. can anyone else confirm?
EDIT2: The real issue is here https://github.com/microsoft/WSL/issues/4739 and I was able to resolve my problem by integrating Docker with my Ubuntu WSL2 distro, and putting my file system in the Linux-mounted \wsl$ file system. Now fsnotify is properly detecting changes, and Air works!
I am also experiencing this... on Intel.. I wonder if related to a new version of Docker or something? Maybe fsnotify for some particular reason/stack not working with mounted volumes? Will continue looking but thought I'd post here to show support. Works fine locally, without Docker.
EDIT: Seems potentially related from mounted volumes on Docker for Windows/WSL not firing the necessary I/O events.. can anyone else confirm?
EDIT2: The real issue is here microsoft/WSL#4739 and I was able to resolve my problem by integrating Docker with my Ubuntu WSL2 distro, and putting my file system in the Linux-mounted \wsl$ file system. Now fsnotify is properly detecting changes, and Air works!
Good for you, if it's not an ARM thing, then I'll wait for Air to get updated :)
Checking in - @kockok did you ever find a resolution for this? I'm running into the exact same problem setting up air to run w/ docker on my M1.
Checking in - @kockok did you ever find a resolution for this? I'm running into the exact same problem setting up air to run w/ docker on my M1.
Negative, I switched to CompileDaemon
tentatively, but really want air instead...
Checking in - @kockok did you ever find a resolution for this? I'm running into the exact same problem setting up air to run w/ docker on my M1.
Negative, I switched to
CompileDaemon
tentatively, but really want air instead...
Gotcha. Is there an existing issue that addresses this? If not shouldn't this one be reopened?
I'm new to Go, but I'm having the same problem.
Windows 10, Go 1.19, AMD
My simple sample project structure and code looks like this:
...which results in a simple page that looks like this:
So I go to make a change in main.go
, like changing hello world to something else and save:
...but the terminal output doesn't change at all, like Air SAYS it's "watching" for changes, but when I save, nothing happens in the output.
So then, even after clearing browser cache, and using a new incognito window, the change doesn't even reflect on the page:
Forgive my newbie-ness, but what's happening here?
One thing that might be worth mentioning here is that I’m running this inside a docker-compose. Maybe it doesn’t apply changes saved in a container, but only on local instances of the app?
I'm fairly confident that the issue is due to fsnotify
not picking up file system events between the Linux/Ubuntu Docker file system (LFTS), and the Windows file system (NFTS) which is making the changes through the mounted volume (such as.. through VSCode/etc.). I believe the only good solution is for air
to implement polling... so until then, as @kockok has done, I have switched to CompileDaemon
(or similar) which offers polling (this is less efficient as it doesn't utilize events and instead just checks all your project files for changes every X milliseconds, but necessary for mixing file systems).
(Or, fsnotify could add polling themselves, but this has been open since 2014: https://github.com/fsnotify/fsnotify/issues/9#issue-36736290)
(Alternatively, you can standardize on a singular file system.. such as pairing Docker with WSL2 and working out of the \\wsl$ directory as I described above. I found this had some other side effects down the road so I reverted, but it is a solution)
Thus, this issue is better closed in favor of/described by #190 (or the earlier, but less discussed, #67).
Just noticed my Docker Desktop in Linux use virtiofs in container, so I tried disable it thourgh "~/.docker/desktop/settings.json" setting "useVirtualizationFrameworkVirtioFS": true -> "useVirtualizationFrameworkVirtioFS": false. After that Docker Desktop stop running. And I just installed usual docker :), and now hot reload is working. So, maybe in Windows or Mac you can change this parameter and Docker Desktop will run, and you maybe will get working hot reload, but I can't test it myself.
Just noticed my Docker Desktop in Linux use virtiofs in container, so I tried disable it thourgh "~/.docker/desktop/settings.json" setting "useVirtualizationFrameworkVirtioFS": true -> "useVirtualizationFrameworkVirtioFS": false. After that Docker Desktop stop running. And I just installed usual docker :), and now hot reload is working. So, maybe in Windows or Mac you can change this parameter and Docker Desktop will run, and you maybe will get working hot reload, but I can't test it myself.
I tried this. Unfortunately does not work, after I set useVirtualizationFrameworkVirtioFS:false
docker always failed to start.
Updating Docker Engine to the latest version seems to solve the issues with air to me.
mine still doesn't work even after updating the docker engine version to 20.10.22
I tried both versions and neither detected a difference on Docker. macOS: 13.1 M1 MacBook
Server: Docker Engine - Community
Engine:
Version: 20.10.12
API version: 1.41 (minimum version 1.12)
Go version: go1.16.12
Git commit: 459d0df
Built: Mon Dec 13 11:43:07 2021
OS/Arch: linux/arm64
Experimental: false
Server: Docker Desktop 4.16.2 (95914)
Engine:
Version: 20.10.22
API version: 1.41 (minimum version 1.12)
Go version: go1.18.9
Git commit: 42c8b31
Built: Thu Dec 15 22:25:43 2022
OS/Arch: linux/arm64
Experimental: false
Sorry to hear that. By the way, this is my docker-compose.yaml
file just in case anyone needs it.
Also, this is my
Dockerfile
.
I'm facing the same issue in Windows 11 on Docker v20.10.22
WIndows 10, Docker v20.10.22, ditto. Working if run air from terminal, not working if run it from docker compose.
Unfortunately, I have the same problem. Initial build works, but no luck getting anything updated.
Edition Windows 10 Pro
Version 22H2
Installed on 2020-08-23
OS build 19045.2604
Experience Windows Feature Experience Pack 120.2212.4190.0
Docker Engine
v20.10.22
.air.toml
[build]
cmd = "go build -o ./tmp/api ./cmd/api"
bin = "tmp/api"
docker-compose.yml
services:
app:
build:
context: .
dockerfile: Dockerfile
target: air
ports:
- 8080:8080
volumes:
- ./:/app
I haven't tried yet but maybe for when working from vscode Devcontainer could be the solution taking into account it'll handle the container file system, here's a small example about that: https://github.com/devmeireles/go-shop-store
By the end of the day I moved to CompileDaemon
I had same issue but only forget docker-compose a volume-mount setting . My PC: mac M1 docker-comopse.yml
.
├── app/
│ ├── ...go application
│ └── air.toml
├── dockerfile
└── docker-compose.yml
web:
container_name: go_app
volumes:
...
- ./app:/app #← add this
VScode alternative solution is to use Dev Container and Docker Extensions (by Microsoft.com).
Connect to the container via instructions provided by Dev Container and navigate to the working directory through the explorer (you may be defaulted to /root/) and file changes will reload with Air.
With the volume type mount, I haven't seen any issues arise in the remote vscode instance; however, this still has no effect on the host vscode instance, as there seems to be no response with file changes in Air. So you must use the remote vscode instance.
I haven't tested with a remote docker instance either, as I am hosting docker on the host machine.
note: vscode dev container instance will not have your extensions.
I'm on windows, i thought it may be a permission issue, so i started vscode and docker as administrator, but no luck. the only solution i found was to make air to use polling instead of events, so what you should do is basically change poll to true and it should work
# Poll files for changes instead of using fsnotify.
poll = true
I'm on windows, i thought it may be a permission issue, so i started vscode and docker as administrator, but no luck. the only solution i found was to make air to use polling instead of events, so what you should do is basically change poll to true and it should work
# Poll files for changes instead of using fsnotify. poll = true
Excellent answer. It works for me.
i have just changed in the .air.toml [build] poll = true
The perfect solution 💕
Issue: Air is starting but not reloading on changes in the project
Solution: In .air.toml file add poll = true This is because Windows has some restrictions and to overcome that we set poll to true
Solution in code:
poll = true
I think it's solved
It's the docker issue for me. Just updat to the latest docker app.
I'm new to Go, but I'm having the same problem.
Windows 10, Go 1.19, AMD
My simple sample project structure and code looks like this:
...which results in a simple page that looks like this:
So I go to make a change in
main.go
, like changing hello world to something else and save:
...but the terminal output doesn't change at all, like Air SAYS it's "watching" for changes, but when I save, nothing happens in the output.
So then, even after clearing browser cache, and using a new incognito window, the change doesn't even reflect on the page:
Forgive my newbie-ness, but what's happening here?
i have this problem just quite terminal and run air command again.
I'm new to Go, but I'm having the same problem.
Windows 10, Go 1.19, AMD
My simple sample project structure and code looks like this:
...which results in a simple page that looks like this:
So I go to make a change in
main.go
, like changing hello world to something else and save:
...but the terminal output doesn't change at all, like Air SAYS it's "watching" for changes, but when I save, nothing happens in the output.
So then, even after clearing browser cache, and using a new incognito window, the change doesn't even reflect on the page:
Forgive my newbie-ness, but what's happening here?
i have this problem just quite terminal and run air command again.
Try changing your browser or just follow my solution
poll = true
it works for me, thanks
Polling is not a performant solution. What is the underlying issue here?
I have tested on Arch and Windows and both platforms suffer from the same issue.
[mason@mason-surfarch ~]$ docker version Client: Version: 24.0.7 API version: 1.43 Go version: go1.21.3 Git commit: afdd53b4e3 Built: Sun Oct 29 15:42:02 2023 OS/Arch: linux/amd64 Context: default
Server: Engine: Version: 24.0.7 API version: 1.43 (minimum version 1.12) Go version: go1.21.3 Git commit: 311b9ff0aa Built: Sun Oct 29 15:42:02 2023 OS/Arch: linux/amd64 Experimental: false containerd: Version: v1.7.11 GitCommit: 64b8a811b07ba6288238eefc14d898ee0b5b99ba.m runc: Version: 1.1.10 GitCommit:
docker-init: Version: 0.19.0 GitCommit: de40ad0 [mason@mason-surfarch ~]$ uname -a Linux mason-surfarch 6.6.6-arch1-1-surface #1 SMP PREEMPT_DYNAMIC Wed, 13 Dec 2023 21:27:25 +0000 x86_64 GNU/Linux [mason@mason-surfarch ~]$
The perfect solution 💕
Issue: Air is starting but not reloading on changes in the project
Solution: In .air.toml file add poll = true This is because Windows has some restrictions and to overcome that we set poll to true
Solution in code:
poll = true
it works for me