Golang Mac OSX build for Docker machine

Viewed 2897

I need to run Golang application on Docker machine.

I'm working on Mac OSX and Docker is working on top of Linux virtual machine, so binaries builded on Mac are not runnable on Docker.

I see two ways here:

  1. cross-compile binaries on Mac for linux OS
  2. copy project sources to docker, run 'go get' and 'go build' on it

First one is hard because of CGO (it is used in some imported libraries).

Second is very slow because of 'go get' operation.

Can you please tell me, which way is the most common in that situation? Or maybe I'm doing something wrong?

3 Answers

You could create a Docker container from the distinct OS you need for your executable, and map a volume to your src directory. Run the container and make the executable from within the container. You end up with a binary that you can run on the distinct OS.

Related