skip to Main Content

I’m facing an issue, am trying to run my go fiber project inside docker with air but am getting this error
uni-blog | /bin/sh: 1: /app/tmpmain.exe: not found

am using
Windows 11
Docker desktop
golang latest
air 1.27.10
fiber latest

Here is my docker compose and dockerfile

# docker-compose up -d --build
version: "3.8"

services:
  app:
    container_name: uni-blog
    image: app-dev
    build:
      context: .
      target: development
    volumes:
      - ./:/app
    ports:
      - 3000:3000

FROM golang:1.17 as development

RUN apt update && apt upgrade -y && 
  apt install -y git 
  make openssh-client

RUN curl -fLo install.sh https://raw.githubusercontent.com/cosmtrek/air/master/install.sh 
    && chmod +x install.sh && sh install.sh && cp ./bin/air /bin/air

RUN air -v

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download

COPY . .

EXPOSE 3000

CMD air

I also tried installing air following the readME instructions still it gives me this error
Please help

Thanks in advance

image

image

2

Answers


  1. The volumes: mount you have replaces the /app directory in the image with content from the host. If the binary is built in the Dockerfile, that volumes: mount hides it; if you don’t have a matching compatible binary on the host in the same place, you’ll get an error like what you see.

    I’d remove that volumes: block so you’re actually running the binary that’s built into the image. The docker-compose.yml file can be reduced to as little as:

    version: '3.8'
    services:
      app:
        build: .
        ports:
          - '3000:3000'
    
    Login or Signup to reply.
  2. If you look the error, you ca notice there is a typo between tmp/main.exe:

    /bin/sh: 1: /app/tmpmain.exe: not found
    

    This is coming from .air.toml config file:

        bin = "tmp\main.exe"
    

    Create .air.toml file in project root like so:

    root = "."
    tmp_dir = "tmp"
    
    [build]
    
      # Build binary.
      cmd = "go build -o ./tmp/main.exe ."
    
      # Read binary.
      bin = "tmp/main.exe"
    
      # Watch changes in those files
      include_ext = [ "go", "yml"]
    
      # Ignore changes in these files
      exclude_dir = ["tmp"]
    
      # Stop builds from triggering too fast
      delay = 1000 # ms
    
    [misc]
      clean_on_exit = true
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search