简体   繁体   中英

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.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM