1. golang:latest base image mkdir gotest touch main.go touch Dockerfile 1. Example code package main import ( "fmt" "log" "net/http" ) func main() { http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) { fmt.Fprint(writer, "Hello World") }) fmt.Println("3000!!") log.Fatal(http.ListenAndServe(":3000", nil)) } 2. Dockerfile configuration #Source image FROM golang:latest #Set the working directory WORKDIR $GOPATH/src/github.com/gotest #Add the server's go project code to the docker container ADD . $GOPATH/src/github.com/gotest #go build executable file RUN go build . #Expose port EXPOSE 3000 #Finally run the docker command ENTRYPOINT ["./gotest"] 3. Packaging the image docker build -t gotest .
2. alpine:latest base image
#Source image FROM alpine:latest #Set the working directory WORKDIR $GOPATH/src/github.com/common #Add the server's go project code to the docker container ADD . $GOPATH/src/github.com/common #Expose port EXPOSE 3002 #Finally run the docker command ENTRYPOINT ["./common"] Packaging image docker build -t common . This is the end of this article about the implementation of two basic images for Docker deployment of Go. For more relevant content about Docker deployment of Go images, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Vue implements the magnifying glass effect of tab switching
>>: Vue Basics Introduction: Vuex Installation and Use
Table of contents Requirements: Implementation st...
There are two ways to export csv in win10. The fi...
First method Alibaba Cloud and Baidu Cloud server...
MySQL SQL statement performance tuning simple exa...
Today I got familiar with the mouse zooming effect...
The notepad program is implemented using the thre...
A while ago, I wrote a blog post titled "Can...
1. Insert the wireless network card and use the c...
Optimistic Locking Optimistic locking is mostly i...
Table of contents need: Function Points Rendering...
Preface: Recently, the company project changed th...
Inserting images into HTML requires HTML tags to ...
This tutorial shares the detailed steps of instal...
Because I have always used vscode to develop fron...
PS: I've recently been reading the Nginx chap...