Golangのホットリロードツールである「Air」のコマンド .air.toml 内の 単純に、Windows系とUNIX系のパスの違い(参考)が原因でした...(^-^;) 以上です。 最後まで読んでいただきありがとうございました!環境
エラー
air init
で初期設定ファイル .air.toml を自動で出力したあとに、
Docker経由( docker-compose up
)で開始コマンド air
を実行したところ、途中でエラーが出る。PS C:\Users\<user_name>\<project_dir>\golang-test> docker-compose up
[+] Running 1/0
- Container golang-test-app-1 Created 0.0s
Attaching to golang-test-app-1
golang-test-app-1 |
golang-test-app-1 | __ _ ___
golang-test-app-1 | / /\ | | | |_)
golang-test-app-1 | /_/--\ |_| |_| \_ , built with Go
golang-test-app-1 |
golang-test-app-1 | [23:56:56] watching .
golang-test-app-1 | [23:56:56] !exclude tmp
golang-test-app-1 | [23:56:56] building...
golang-test-app-1 | [23:56:56] running...
golang-test-app-1 | /bin/sh: 1: /go/src/app/tmpmain.exe: not found
修正前
version: '3'
services:
app:
build: .
volumes:
- ./:/go/src/app
ports:
- "8080:8080"
FROM golang:1.20
ENV ROOT=/go/src/app
WORKDIR ${ROOT}
COPY . .
EXPOSE 8080
# Airをインストール → 実行
RUN go install github.com/cosmtrek/air@latest
CMD ["air"]
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"
[build]
args_bin = []
bin = "tmp\\main.exe"
cmd = "go build -o ./tmp/main.exe ."
delay = 0
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false
[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"
[log]
main_only = false
time = false
[misc]
clean_on_exit = false
[screen]
clear_on_rebuild = false
keep_scroll = true
解決策
bin = "tmp\\main.exe"
を bin = "tmp/main.exe"
に修正する。修正後
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"
[build]
args_bin = []
bin = "tmp/main.exe" # ← ココ(修正箇所)
cmd = "go build -o ./tmp/main.exe ."
delay = 0
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false
[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"
[log]
main_only = false
time = true
[misc]
clean_on_exit = false
[screen]
clear_on_rebuild = false
keep_scroll = true
補足
修正前の状態でも、Docker上ではなくWindowsのローカル上、つまり直接 air
コマンドから実行すると当然エラーは出ません。
Macであれば、UNIX系のパス(bin = "tmp/main.exe")で .air.toml を出力してくれるため、特に修正は不要でした。
自己紹介
かわいち
都内ではたらくWeb系エンジニアです! 普段から効率良く開発できるように心がけています。 また、趣味でもプログラミングをしており、モノづくりが好きです。 このブログでは、プログラミングに役立つコトを日々発信しています!