update readme.md for all samples
Signed-off-by: Anca Iordache <anca.iordache@docker.com>
This commit is contained in:
		
							
								
								
									
										78
									
								
								samples/nginx-golang/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										78
									
								
								samples/nginx-golang/README.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,78 @@ | ||||
| ## Compose sample application | ||||
| ### NGINX proxy with GO backend | ||||
|  | ||||
| Project structure: | ||||
| ``` | ||||
| . | ||||
| ├── backend | ||||
| │   ├── Dockerfile | ||||
| │   └── main.go | ||||
| ├── docker-compose.yml | ||||
| ├── frontend | ||||
| │   ├── Dockerfile | ||||
| │   └── nginx.conf | ||||
| └── README.md | ||||
| ``` | ||||
|  | ||||
| [_docker-compose.yaml_](docker-compose.yaml) | ||||
| ``` | ||||
| version: "3.7" | ||||
| services: | ||||
|   frontend: | ||||
|     build: frontend | ||||
|     ports: | ||||
|     - 8080:80 | ||||
|   backend: | ||||
|     build: backend | ||||
| ``` | ||||
| The compose file defines an application with two services `frontend` and `backend`. | ||||
| When deploying the application, docker-compose maps port 80 of the frontend service container to port 8080 of the host as specified in the file. | ||||
| Make sure port 8080 on the host is not already being in use. | ||||
|  | ||||
| ## Deploy with docker-compose | ||||
|  | ||||
| ``` | ||||
| $ docker-compose up -d | ||||
| Creating network "nginx-golang_default" with the default driver | ||||
| Building backend | ||||
| Step 1/7 : FROM golang:1.13 AS build | ||||
| 1.13: Pulling from library/golang | ||||
| ... | ||||
| Successfully built 4b24f27138cc | ||||
| Successfully tagged nginx-golang_frontend:latest | ||||
| WARNING: Image for service frontend was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`. | ||||
| Creating nginx-golang_backend_1 ... done | ||||
| Creating nginx-golang_frontend_1 ... done | ||||
| ``` | ||||
|  | ||||
| ## Expected result | ||||
|  | ||||
| Listing containers must show two containers running and the port mapping as below: | ||||
| ``` | ||||
| $ docker ps | ||||
| CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES | ||||
| 8bd5b0d78e73        nginx-golang_frontend   "nginx -g 'daemon of…"   53 seconds ago      Up 52 seconds       0.0.0.0:8080->80/tcp   nginx-golang_frontend_1 | ||||
| 56f929c240a0        nginx-golang_backend    "/usr/local/bin/back…"   53 seconds ago      Up 53 seconds                              nginx-golang_backend_1 | ||||
| ``` | ||||
|  | ||||
| After the application starts, navigate to `http://localhost:8080` in your web browser or run: | ||||
| ``` | ||||
| $ curl localhost:8080 | ||||
|  | ||||
|           ##         . | ||||
|     ## ## ##        == | ||||
|  ## ## ## ## ##    === | ||||
| /"""""""""""""""""\___/ === | ||||
| {                       /  ===- | ||||
| \______ O           __/ | ||||
|  \    \         __/ | ||||
|   \____\_______/ | ||||
|  | ||||
| 	 | ||||
| Hello from Docker! | ||||
| ``` | ||||
|  | ||||
| Stop and remove the containers | ||||
| ``` | ||||
| $ docker-compose down | ||||
| ``` | ||||
							
								
								
									
										11
									
								
								samples/nginx-golang/backend/Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								samples/nginx-golang/backend/Dockerfile
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| FROM golang:1.13 AS build | ||||
|  | ||||
| WORKDIR /compose/hello-docker | ||||
| COPY main.go main.go | ||||
| RUN CGO_ENABLED=0 go build -o backend main.go | ||||
|  | ||||
| FROM scratch | ||||
| COPY --from=build /compose/hello-docker/backend /usr/local/bin/backend | ||||
| CMD ["/usr/local/bin/backend"] | ||||
|  | ||||
|  | ||||
							
								
								
									
										30
									
								
								samples/nginx-golang/backend/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								samples/nginx-golang/backend/main.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | ||||
| package main | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"log" | ||||
| 	"net/http" | ||||
| ) | ||||
|  | ||||
| func handler(w http.ResponseWriter, r *http.Request) { | ||||
| 	fmt.Println(r.URL.RawQuery) | ||||
| 	fmt.Fprintf(w, ` | ||||
|           ##         . | ||||
|     ## ## ##        == | ||||
|  ## ## ## ## ##    === | ||||
| /"""""""""""""""""\___/ === | ||||
| {                       /  ===- | ||||
| \______ O           __/ | ||||
|  \    \         __/ | ||||
|   \____\_______/ | ||||
|  | ||||
| 	 | ||||
| Hello from Docker! | ||||
|  | ||||
| `) | ||||
| } | ||||
|  | ||||
| func main() { | ||||
| 	http.HandleFunc("/", handler) | ||||
| 	log.Fatal(http.ListenAndServe(":80", nil)) | ||||
| } | ||||
							
								
								
									
										12
									
								
								samples/nginx-golang/docker-compose.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								samples/nginx-golang/docker-compose.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
|  | ||||
| version: "3.7" | ||||
| services: | ||||
|   frontend: | ||||
|     build: frontend     | ||||
|     ports: | ||||
|     - 8080:80 | ||||
|     depends_on: | ||||
|     - backend | ||||
|   backend: | ||||
|     build: backend | ||||
|  | ||||
							
								
								
									
										4
									
								
								samples/nginx-golang/frontend/Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								samples/nginx-golang/frontend/Dockerfile
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| FROM nginx:alpine  | ||||
| COPY nginx.conf /etc/nginx/conf.d/default.conf | ||||
|  | ||||
|  | ||||
							
								
								
									
										6
									
								
								samples/nginx-golang/frontend/nginx.conf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								samples/nginx-golang/frontend/nginx.conf
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| server { | ||||
|   listen 80; | ||||
|   location / { | ||||
|     proxy_pass http://backend:80; | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user