Docker Deployment Golang

Source: Internet
Author: User
Tags docker run

1. Installing Docker

2. mkdir Mydocker

3. CD Mydocker && Touch Dockerfile

4. Dockerfile Write

# Use the Golang environment as the parent image

 from Golang Maintainer Razil "zc6496359"workdir  $GOPATH/src/godockerADD  . $GOPATH/src/godocker RUN Go build main.go EXPOSE 8080entrypoint ["./main"]

Parameter explanation:

 from maintainerworkdirADD RUN   EXPOSEentrypoint , program entrance

5. Write the Main.go file under Mydocker

6. Build the image

The description constitutes success.

7. Docker images view the created image

8. Docker Run-p 8080:8080-d Zcdocker

-P native Port: Mirrored port

-D Background Run

9. Native Access localhost:8080/zc returns Hello Docker Form golang! success

Main.go content is as follows

Package MainImport(    "net/http"    "FMT") Func Main () {http. Handlefunc ("/zc", hello) http. Listenandserve (": 8080", Nil)} Func Hello (w http. Responsewriter, R*http. Request) {fmt. fprintf (W,"Hello Docker Form golang!")}

Related Article

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.