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