Deploying Golang with Docker

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/godocker

ADD. $GOPATH/src/godocker

RUN Go Build main.go

EXPOSE 8080

entrypoint ["./main"]

Parameter explanation:

From-and mother image

Maintainer, maintainer information

Working Directory Workdir

Copy files to the mirror from add

Run and execute (just as the terminal executes the statement)

Exposed Port EXPOSE

entrypoint, program entrance

5. Write the Main.go file under Mydocker

6. Build the image

Docker build-t Zcdocker.

There is a successfully build ...

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 Main

Import

"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.