-2

I have the following dockerfile and everything works fine except for running the .exe

FROM golang:latest

# Set the Current Working Directory inside the container
WORKDIR $GOPATH/src/github.com/user/goserver

# Copy everything from the current directory to the PWD (Present Working Directory) inside the container
COPY . .

# Download all the dependencies
RUN go get -d -v ./...

# Install the package
RUN GOOS=linux GOARCH=amd64 go build -o goserver .

# This container exposes port 8080 to the outside world
EXPOSE 8080

# Run the executable
CMD ./goserver

The problem is that it does not execute './goserver'. I need to manually go into the container and then execute it. Any idea what could be going wrong here ?

tmp dev
  • 8,043
  • 16
  • 53
  • 108

1 Answers1

1

The problem is the way you are running the container.

By running the container with the following:

docker run -it -p 8080:8080 goserver /bin/bash

you are overriding the command defined with CMD in Dockerfile to bin/bash command.

You can start the container in detached mode by running it as:

docker run -d -p 8080:8080 goserver

Further, if you want to later exec into the container then you can use the docker exec command.

Krishna Chaurasia
  • 8,924
  • 6
  • 22
  • 35
  • 1
    I would suggest to read the answers to the question [difference between `CMD` and `ENTRYPOINT`](https://stackoverflow.com/questions/21553353/what-is-the-difference-between-cmd-and-entrypoint-in-a-dockerfile) – Krishna Chaurasia Mar 03 '21 at 07:32