こんにちはRujuuです。
今回は「/app/tmpmain.exe: not found」の解決方法を紹介します。
Echoでバックエンドの開発をしていて、ホットリロードを行うためにairを導入したところ以下の様な「/app/tmpmain.exe: not found」エラーが出ました。
- Docker Desktop 4.10.1
- Go 1.20.4
- Echo v4.10.2
- air 1.43.0 https://github.com/cosmtrek/air/releases/tag/v1.43.0
必要ないかもしれませんが、Dockerfileとdocker-compose.ymlのコードも載せておきます。
Dockerfile
FROM golang:1.20-bullseye
ENV TZ /usr/share/zoneinfo/Asia/Tokyo
WORKDIR /app
RUN apt-get update && apt-get install -y tree vim
RUN go install github.com/cosmtrek/air@latest
COPY go.mod go.sum ./
RUN go mod download && go mod verify
docker-compose.yml
version: "3.8"
services:
echo:
container_name: echo
build: .
volumes:
- .:/app
tty: true
ports:
- "8080:8080"
networks:
- backend
postgres:
image: postgres:15.1-alpine
ports:
- 5432:5432
environment:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: test
restart: always
networks:
- backend
networks:
backend:
「air init」で生成される「.air.toml」のbinのpathを書き換えると正常に動きます。
以下のコードでいうと7行目です。
.air.toml
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"
poll = false
poll_interval = 0
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
.air.toml
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"
poll = false
poll_interval = 0
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
これで以下のように、airが正常に動くようになったと思います!
ここまで読んでくださり、ありがとうございました!
airに触れたのは初めてなので、もしより良い解決方法などありましたらコメントなどで優しく教えていただけると嬉しいです。
良いGoライフを✨