How to handle make missing from alpine docker image?

Viewed 10912

i have Makefiles on my app , and all my commands on Makefile i put this on Dockerfile:

# start from the latest golang base image
FROM golang:alpine


RUN apk update && apk add --no-cache gcc && apk add --no-cache libc-dev

# Set the current working Directory inside the container
WORKDIR /app

# Copy go mod and sum files
COPY go.mod go.sum ./

# Download all dependencies. they will be cached of the go.mod and go.sum files are not changed
RUN go mod download

# Copy the source from the current directory to the WORKDIR inisde the container
COPY . .

# Build the Go app
RUN go build .

# Exporse port 3000 or 8000 to the outisde world
EXPOSE 3000

# Command to run the executable
CMD ["make", "-C", "scripts", "test" ]
CMD ["make", "-C", "scripts", "prod" ]

and got

docker: Error response from daemon: OCI runtime create failed: 
        container_linux.go:349: starting container process caused "exec: 
        \"make\": executable file not found in $PATH": unknown.

is it possible to run make -c scripts test in Docker? how to correct way to use this command in Docker?

in dockerfile i run golang:alpine

1 Answers

if you wish to avoid adding all dependencies of make to your alpine image and keep the shipping container small in size:

  • build your binary outside ur container and copy only the shippable binary to ur alpine container
  • build your binary in a normal golang container then copy the binary to a small shippable alpine container
  • you could give https://github.com/go-task/task a try, does not require too many dependencies compared to installing make in ur alpine container and replace ur make file with task file.
Related