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!")
}