Golang on-line project deployment Toss the two

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.
The
basic needs of the software have been installed in the above, it is time to play the real.

Create a project

In order to quickly create an example application, we use the Beego Bee tool. (In this example, assuming that Gopath is in the path/golang, the path to our example project should be/golang/src/demo-test) through the following command:

cd /goLang/srcbee new demo-testcd demo-testbee run

At this point, the http://localhost:8080 is accessed through the browser and the following page is displayed

Create Dockerfile

The final generated dockerfile content is as follows:

FROM golang:1.9RUN go get github.com/astaxie/beego && go get github.com/beego/bee# 通过开发计算机上容器的8080端口暴露该应用程序。EXPOSE 8080# 使用bee命令开始对我们的应用程序进行实时重载。CMD ["bee", "run"]

Build image

After you create the Docker file, you can run the following command to create the image:

docker build -t demo-test .  //后面".",代表当前目录

To view a list of images in your system, run the following command:

docker images

Running the container

demo-testwhen you're ready, you can start a container by using the following command:

docker run -it --name web-demo -p 8080:8080  -v /golang/demo-test:/go/src/demo-test -w /go/src/demo-test demo-test
we have some simple explanations for the commands executed:

docker runCommands can be used to run containers through mirroring

-itTag launches the container using interactive mode

--name web-demoName the containerweb-demo

-p 8080:8080The container 8080 port is mapped to the host 8080 port, and finally we can 8080 access the contents of the container through the port of the host.

-v /golang/demo-test:/go/src/demo-test, use the volume directory that will /golang/demo-test map from the computer to the container /go/src/demo-test

-w /go/src/demo-testSet the working directory of the Container

web-demoSpecifies the name of the mirror used by the container

When the container is started, we can verify that the container is functioning properly by accessing it http://localhost:8080来 .

In fact, this is the micro-service , want to know the specific words, you can see Ruan a peak of the blog:
Http://www.ruanyifeng.com/blo ...

That's it

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.