Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Golang] (Cross)Compile app inside the container -- myapp outside GOPATH #1120

Closed
DazWilkin opened this issue Jan 12, 2018 · 1 comment
Closed

Comments

@DazWilkin
Copy link

For the useful ability to (cross)compile inside the container, is there a reason to recommend mapping myapp outside of GOPATH (currently: /usr/src/myapp)? Or is this an oversight?

I'm exploring using the golang container to compile programs and it seems (to this noob) that myapp would be better mapped within the GOPATH (see below) to support get'ing dependencies.

Currently:

docker run \
--volume=$PWD:/usr/src/myapp \
--workdir=/usr/src/myapp \
--env=GOOS=linux \
--env=GOARCH=amd64 \
golang go build -v

Propose documenting this as:

docker run \
--volume=$PWD:/go/src/myapp \
--workdir=/go/src/myapp \
--env=GOOS=linux \
--env=GOARCH=amd64 \
golang go build -v

which then permits:

docker run \
--volume=$PWD:/go/src/myapp \
--workdir=/go/src/myapp \
--env=GOOS=linux \
--env=GOARCH=amd64 \
golang bash -c 'go get -d ./... && go build .'
@tianon
Copy link
Member

tianon commented Jan 4, 2019

With "Go Modules", GOPATH is now entirely optional, and is what I'd recommend using here. Using /usr/src/myapp is simply an example (it's up to users to adapt to suit their needs based on how Go works, as you've done). 👍

In the future, these sorts of questions/requests would be more appropriately posted to the Docker Community Forums, the Docker Community Slack, or Stack Overflow. Thanks!

@tianon tianon closed this as completed Jan 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants