Dependence on knowledge
Of course, you can also follow these steps to complete the deployment even if you don't know anything about it. However, if there are some small problems in the middle, you may not know how to solve them. Of course, you can also leave a message. I developed and tested it on a Mac. If you are on Windows, there may be some differences, but it shouldn't be a big problem. 1. Dependence on the environment
2. Write a GoLang web program I will write a simplest hello world program here, and the listening port is port 80. package main import ( "fmt" "log" "net/http" ) func sayHello(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "hello world") } func main() { http.HandleFunc("/", sayHello)//Register URI path and corresponding processing function log.Println("[Default project] Service started successfully listening to port 80") er := http.ListenAndServe("0.0.0.0:80", nil) if er != nil { log.Fatal("ListenAndServe: ", er) } } 3. Compile into a package under Linux I developed it on a Mac and needed to use cross-compilation of go. If you are not familiar with cross-compilation, you can check the documentation or just copy the command below to compile. sudo env GOOS=linux GOARCH=386 go build main.go After the compilation is completed, there will be an additional 4. Use Dockerfile to customize the image of our go program Create a new folder, create a new . ├── Dockerfile ├── app │ └── main └── script └── build.sh The following is to write the contents of the FROM golang MAINTAINER Qianyi WORKDIR /go/src/ COPY . . EXPOSE 80 CMD ["/bin/bash", "/go/src/script/build.sh"] Here is the explanation: I paste the content here: #!/usr/bin/env bash cd /go/src/app/ && ./main Just these two lines. 5. Compile our own image This belongs to docker build -t go-web .
Seeing the above output, it means that the compilation is successful, and there is an image named 6. Write the docker-compose.yml file This is our last step. If we use version: '2' networks: basic: services: world: container_name: world image: go-web ports: - "8099:80" volumes: - ./app/go/world:/go/src/app:rw networks: - basic At this point, our orchestration file has been written. Now we just need to use docker-compose -f docker-compose.yml up -d world If the following prompt is output, it means the startup is successful. Creating world ... done After successful startup, you can use docker ps Let's check whether the startup is successful. Now we can access our go program by visiting This is the end of this article about the steps to deploy a go project based on a Docker image. For more information about deploying a go project with a Docker image, 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:
|
<<: Steps to modify the MySQL database data file path under Linux
>>: Native js imitates mobile phone pull-down refresh
Table of contents 1. Transition from development ...
We all know that we can use the mkdir command to ...
Download MySQL-8.0.23 Click to download: mysql-8....
I use tengine, the installation directory is /usr...
1. Enter the configuration file of the yum source...
This article example shares the specific code of ...
Anyone who has read my articles recently knows th...
01. Command Overview The locate command is actual...
eureka: 1. Build a JDK image Start the eureka con...
1. Use CSS, jQuery, and Canvas to create animatio...
Table of contents 1. React Hooks vs. Pure Functio...
Responsive design is to perform corresponding ope...
Float is often used in web page layout, but the f...
Table of contents What is Docker Compose Requirem...
Table of contents 01 Introduction to MySQL Router...