Docker runs a Golang program

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Build a MySQL Environment

Mysql.app

docker run --net=host -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=letchat -d  hub.c.163.com/library/mysql:latest

1. Compile and run the Golang program in the current directory via the container (dependencies need to be downloaded to the current directory vendor first)

Gobuild.app

docker run --net=bridge --rm -v $PWD:/go/src/app -w /go/src/app hub.c.163.com/library/golang:latest  go build -v

2. Use Docker to build the image, run a container on this image, run the Golang program using that container

Dockerfile

FROM hub.c.163.com/library/golang:latestWORKDIR /go/src/appCOPY . .#RUN go-wrapper download   # \"go get -d -v ./...\"RUN go-wrapper install    # \"go install -v ./...\"CMD ["sh","-c","/go/bin/app"]

Gorun.app

# build image  app# docker build -t app:latest .# set envexport GIN_MODE=release# make the containerdocker run --net=host -it -d app:latest

Choose 1 of 2 ways. The first one is to generate an app directly locally, which can be run directly./app. The second is to run the app inside the container, but the network port uses the host's port, which is equivalent to running directly on the local computer.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.