Ananth Upadhya
Ananth Upadhya

Reputation: 317

Building and running a docker image for a Go executable

I am trying to containerize my Go applicaton. I am using Docker to do this. I have a fully executable Docker application running in my system. To run this in a container i am have created a Dockerfile.

FROM golang:1.7
EXPOSE "portno"

I have kept my dockerfile very simple because i already have an executable file running in my system. Please help me what all contents should i add to get the go app running. I am not able to run the go app as many of the contents are not getting copied in container.

Upvotes: 2

Views: 3269

Answers (1)

hypnoglow
hypnoglow

Reputation: 1593

You need to add your executable file to your container using ADD command:

ADD ./app /go/bin/app 

And then you need to tell docker that it should be executed as the main container process:

CMD ["/go/bin/app"]

Note that it may be better to build your application from the source code inside your container. It can be done when you build your docker image. As an example, see this article for more information: http://thenewstack.io/dockerize-go-applications/

Upvotes: 4

Related Questions