Deploying Docker Image applications

Overview

This document is a hands-on guide to deploy a simple Docker Image web application.

Creating the app

To create an app, you need to use the command app-create:

  1. $ tsuru app-create <app-name> <app-platform>

For Docker Images, doesn’t exist a specific platform, but we can use static! Let’s be over creative and develop a helloworld tutorial-app, let’s call it “helloworld”:

  1. $ tsuru app-create helloworld static

To list all available platforms, use the command platform-list.

You can see all your applications using the command app-list:

  1. $ tsuru app-list
  2. +-------------+-------------------------+--------------------------------+
  3. | Application | Units State Summary | Address |
  4. +-------------+-------------------------+--------------------------------+
  5. | helloworld | 0 of 0 units in-service | helloworld.192.168.50.4.nip.io |
  6. +-------------+-------------------------+--------------------------------+

Application code

A simple Dockerfile:

  1. FROM golang
  2. RUN mkdir /app
  3. WORKDIR /app
  4. ADD . /app/
  5. RUN go build .
  6. ENTRYPOINT ./app

A simple web application in Go main.go:

  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "net/http"
  6. "os"
  7. )
  8.  
  9. func main() {
  10. c := make(chan os.Signal, 1)
  11. signal.Notify(c, os.Interrupt)
  12. go func(){
  13. for sig := range c {
  14. if sig == os.Interrupt || sig == os.Kill {
  15. os.Exit(1)
  16. }
  17. }
  18. }()
  19. http.HandleFunc("/", hello)
  20. fmt.Println("running on "+os.Getenv("PORT"))
  21. http.ListenAndServe(":"+os.Getenv("PORT"), nil)
  22. }
  23.  
  24. func hello(res http.ResponseWriter, req *http.Request) {
  25. fmt.Fprintln(res, "hello, world!")
  26. }

Building the image

  1. docker login registry.myserver.com
  2.  
  3. docker build -t registry.myserver.com/image-name .

Don’t forget the dot(.) at the end of the command, this indicates where the Dockerfile is placed

Sending the image to registry

  1. docker push registry.myserver.com/image-name

Docker Image deployment

After pushing your image to your Docker image registry, you can do the deploy using the command tsuru app-deploy -i.

  1. tsuru app-deploy -i registry.myserver.com/image-name -a helloworld

Note

This image should be in a registry and be accessible by the nodes.Image should also have a Entrypoint or a Procfile at given paths, / or /app/user/ or /home/application/current

Running the application

Now that the app is deployed, you can access it from your browser, getting theIP or host listed in app-list and opening it. For example,in the list below:

  1. $ tsuru app-list
  2. +-------------+-------------------------+--------------------------------+
  3. | Application | Units State Summary | Address |
  4. +-------------+-------------------------+--------------------------------+
  5. | helloworld | 1 of 1 units in-service | helloworld.192.168.50.4.nip.io |
  6. +-------------+-------------------------+--------------------------------+

It’s done! Now we have a simple Docker image project deployed on tsuru.

Now we can access your app in the URL displayed in app-list(“helloworld.192.168.50.4.nip.io” in this case).

Going further

For more information, you can dig into tsuru docs, orread complete instructions of use for the tsuru command.

原文: https://docs.tsuru.io/1.6/using/docker-image.html