Getting windows executable binaries from docker

Im running docker using windows containers and i need to build my image and then get windows compiled executables for my app. Here is my Dockerfile

FROM golang:nanoserver
COPY . .
RUN go build -o app
CMD ["./app"]

This is what im working with

set GOARCH=amd64
set GOEXE=.exe
set GOOS=windows

My image gets built successfully and if there was a RUN dir in Dockerfile, you’ll see that the executables are present.
But when i try to run a container from that image like this, docker run -p 8080:8080 webapp, i get this err

docker: Error response from daemon: container 791b7108a0a8dc7ec7b89e619707a6d97858a5483cc2089856076fc2019bf264 encountered an error during hcsshim::System::CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2)
[Event Detail:  Provider: 00000000-0000-0000-0000-000000000000]
[Event Detail:  Provider: 00000000-0000-0000-0000-000000000000]
[Event Detail: onecore\vm\compute\management\orchestration\vmhostedcontainer\processmanagement.cpp(173)\vmcomputeagent.exe!00007FF7E0E69D2B: (caller: 00007FF7E0E1E13A) Exception(2) tid(390) 80070002 The system cannot find the file specified.
 Provider: 00000000-0000-0000-0000-000000000000] extra info: {"CommandLine":"./app","User":"ContainerUser","WorkingDirectory":"C:\\src","Environment":{"GOLANG_VERSION":"1.15.6","GOPATH":"C:\\gopath"},"CreateStdInPipe":true,"CreateStdOutPipe":true,"CreateStdErrPipe":true,"ConsoleSize":[0,0]}.

How can i run the container successfully so i can retrieve my binaries and use them?

I removed the last command in my Dockerfile and basically did a docker cp to copy my binary from my container to my host machine.

That container builds an application and tries to run it then. As the container runs linux it can’t run the windows binary.

You might want to only build the image and then use tools like docker cp to extract artifacts. Alternatively volumes where you write the artifacts to and remove the entrypoint (or change it to some other no-op style command)

Yup that works. Was able to copy the binaries. But the status of the container is Exited, and there are no ports published even after i used the -p option. will that in anyway affect my binaries?

To be exact my app simply performs CRUD operations using mongoDB, and running the binaries, a client is connected with no errors, but trying the Ping method will result in a context deadline exceeded error. Dont get that building my app directly from host.

Or its just an issue in the code itself…

If you want to run your service in the docker, then compile it to a Linux binary.

Currently I do not really understand what your goal is.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.