update readme.md for all samples
Signed-off-by: Anca Iordache <anca.iordache@docker.com>master
parent
9c829ac4ba
commit
48341239de
@ -1,11 +0,0 @@
|
||||
FROM golang:1.13 AS builder
|
||||
|
||||
WORKDIR /compose/hello-docker
|
||||
COPY main.go main.go
|
||||
RUN CGO_ENABLED=0 go build -o backend main.go
|
||||
|
||||
FROM scratch
|
||||
COPY --from=builder /compose/hello-docker/backend /usr/local/bin/backend
|
||||
CMD ["/usr/local/bin/backend"]
|
||||
|
||||
|
@ -1,14 +0,0 @@
|
||||
|
||||
version: "3.6"
|
||||
services:
|
||||
frontend:
|
||||
image: nginx
|
||||
ports:
|
||||
- 8080:80
|
||||
volumes:
|
||||
- ./nginx.conf:/etc/nginx/conf.d/default.conf
|
||||
depends_on:
|
||||
- backend
|
||||
backend:
|
||||
build: .
|
||||
|
@ -1,30 +0,0 @@
|
||||
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))
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
server {
|
||||
listen 80;
|
||||
location / {
|
||||
proxy_pass http://backend:80;
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
## Compose sample application
|
||||
### Go server with an Nginx proxy and a MySQL database
|
||||
|
||||
Project structure:
|
||||
```
|
||||
.
|
||||
├── backend
|
||||
│ ├── Dockerfile
|
||||
│ ├── go.mod
|
||||
│ └── main.go
|
||||
├── db
|
||||
│ └── password.txt
|
||||
├── docker-compose.yaml
|
||||
├── proxy
|
||||
│ ├── conf
|
||||
│ └── Dockerfile
|
||||
└── README.md
|
||||
```
|
||||
|
||||
[_docker-compose.yaml_](docker-compose.yaml)
|
||||
```
|
||||
services:
|
||||
backend:
|
||||
build: backend
|
||||
...
|
||||
db:
|
||||
image: mysql:5.7
|
||||
...
|
||||
proxy:
|
||||
build: proxy
|
||||
ports:
|
||||
- 80:80
|
||||
...
|
||||
```
|
||||
The compose file defines an application with three services `proxy`, `backend` and `db`.
|
||||
When deploying the application, docker-compose maps port 80 of the proxy service container to port 80 of the host as specified in the file.
|
||||
Make sure port 80 on the host is not already being in use.
|
||||
|
||||
## Deploy with docker-compose
|
||||
|
||||
```
|
||||
$ docker-compose up -d
|
||||
Creating network "nginx-golang-mysql_default" with the default driver
|
||||
Building backend
|
||||
Step 1/8 : FROM golang:1.13-alpine AS build
|
||||
1.13-alpine: Pulling from library/golang
|
||||
...
|
||||
Successfully built 5f7c899f9b49
|
||||
Successfully tagged nginx-golang-mysql_proxy:latest
|
||||
WARNING: Image for service proxy 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-mysql_db_1 ... done
|
||||
Creating nginx-golang-mysql_backend_1 ... done
|
||||
Creating nginx-golang-mysql_proxy_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
|
||||
8906b14c5ad1 nginx-golang-mysql_proxy "nginx -g 'daemon of…" 2 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp nginx-golang-mysq
|
||||
l_proxy_1
|
||||
13e0e0a7715a nginx-golang-mysql_backend "/server" 2 minutes ago Up 2 minutes 8000/tcp nginx-golang-mysq
|
||||
l_backend_1
|
||||
ca8c5975d205 mysql:5.7 "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 3306/tcp, 33060/tcp nginx-golang-mysq
|
||||
l_db_1
|
||||
```
|
||||
|
||||
After the application starts, navigate to `http://localhost:80` in your web browser or run:
|
||||
```
|
||||
$ curl localhost:80
|
||||
["Blog post #0","Blog post #1","Blog post #2","Blog post #3","Blog post #4"]
|
||||
```
|
||||
|
||||
Stop and remove the containers
|
||||
```
|
||||
$ docker-compose down
|
||||
```
|
@ -0,0 +1,75 @@
|
||||
## Compose sample application
|
||||
### Go server with an Nginx proxy and a Postgres database
|
||||
|
||||
Project structure:
|
||||
```
|
||||
.
|
||||
├── backend
|
||||
│ ├── Dockerfile
|
||||
│ ├── go.mod
|
||||
│ └── main.go
|
||||
├── db
|
||||
│ └── password.txt
|
||||
├── docker-compose.yaml
|
||||
├── proxy
|
||||
│ ├── conf
|
||||
│ └── Dockerfile
|
||||
└── README.md
|
||||
```
|
||||
|
||||
[_docker-compose.yaml_](docker-compose.yaml)
|
||||
```
|
||||
services:
|
||||
backend:
|
||||
build: backend
|
||||
...
|
||||
db:
|
||||
image: postgres
|
||||
...
|
||||
proxy:
|
||||
build: proxy
|
||||
ports:
|
||||
- 80:80
|
||||
...
|
||||
```
|
||||
The compose file defines an application with three services `proxy`, `backend` and `db`.
|
||||
When deploying the application, docker-compose maps port 80 of the proxy service container to port 80 of the host as specified in the file.
|
||||
Make sure port 80 on the host is not already being in use.
|
||||
|
||||
## Deploy with docker-compose
|
||||
|
||||
```
|
||||
$ docker-compose up -d
|
||||
Creating network "nginx-golang-postgres_default" with the default driver
|
||||
Pulling db (postgres:)...
|
||||
latest: Pulling from library/postgres
|
||||
...
|
||||
Successfully built 5f7c899f9b49
|
||||
Successfully tagged nginx-golang-postgres_proxy:latest
|
||||
WARNING: Image for service proxy 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-postgres_db_1 ... done
|
||||
Creating nginx-golang-postgres_backend_1 ... done
|
||||
Creating nginx-golang-postgres_proxy_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
|
||||
5e3ecd0289c0 nginx-golang-postgres_proxy "nginx -g 'daemon of…" 48 seconds ago Up 48 seconds 0.0.0.0:80->80/tcp nginx-golang-postgres_proxy_1
|
||||
ffa1410b1c8a nginx-golang-postgres_backend "/server" 49 seconds ago Up 48 seconds 8000/tcp nginx-golang-postgres_backend_1
|
||||
e63be7db7cbc postgres "docker-entrypoint.s…" 49 seconds ago Up 49 seconds 5432/tcp nginx-golang-postgres_db_1
|
||||
```
|
||||
|
||||
After the application starts, navigate to `http://localhost:80` in your web browser or run:
|
||||
```
|
||||
$ curl localhost:80
|
||||
["Blog post #0","Blog post #1","Blog post #2","Blog post #3","Blog post #4"]
|
||||
```
|
||||
|
||||
Stop and remove the containers
|
||||
```
|
||||
$ docker-compose down
|
||||
```
|
@ -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
|
||||
```
|
@ -1,5 +1,5 @@
|
||||
|
||||
version: "3.6"
|
||||
version: "3.7"
|
||||
services:
|
||||
frontend:
|
||||
build: frontend
|
@ -0,0 +1,87 @@
|
||||
## Compose sample application
|
||||
### React application with a NodeJS backend and a MySQL database
|
||||
|
||||
Project structure:
|
||||
```
|
||||
.
|
||||
├── backend
|
||||
│ ├── Dockerfile
|
||||
│ ...
|
||||
├── db
|
||||
│ └── password.txt
|
||||
├── docker-compose.yaml
|
||||
├── frontend
|
||||
│ ├── ...
|
||||
│ └── Dockerfile
|
||||
└── README.md
|
||||
```
|
||||
|
||||
[_docker-compose.yaml_](docker-compose.yaml)
|
||||
```
|
||||
services:
|
||||
backend:
|
||||
build: backend
|
||||
...
|
||||
db:
|
||||
image: postgres
|
||||
...
|
||||
frontend:
|
||||
build: frontend
|
||||
ports:
|
||||
- 80:9000
|
||||
...
|
||||
```
|
||||
The compose file defines an application with three services `frontend`, `backend` and `db`.
|
||||
When deploying the application, docker-compose maps port 80 of the frontend service container to port 9000 of the host as specified in the file.
|
||||
Make sure port 80 on the host is not already being in use.
|
||||
|
||||
## Deploy with docker-compose
|
||||
|
||||
```
|
||||
$ docker-compose up -d
|
||||
Creating network "react-express-mysql_default" with the default driver
|
||||
Building backend
|
||||
Step 1/16 : FROM node:10
|
||||
---> aa6432763c11
|
||||
...
|
||||
Successfully tagged react-express-mysql_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 react-express-mysql_db_1 ... done
|
||||
Creating react-express-mysql_backend_1 ... done
|
||||
Creating react-express-mysql_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
|
||||
5e3ecd0289c0 nginx-golang-postgres_proxy "nginx -g 'daemon of…" 48 seconds ago Up 48 seconds 0.0.0.0:80->80/tcp nginx-golang-postgres_proxy_1
|
||||
ffa1410b1c8a nginx-golang-postgres_backend "/server" 49 seconds ago Up 48 seconds 8000/tcp nginx-golang-postgres_backend_1
|
||||
e63be7db7cbc postgres "docker-entrypoint.s…" 49 seconds ago Up 49 seconds 5432/tcp nginx-golang-postgres_db_1
|
||||
```
|
||||
|
||||
After the application starts, navigate to `http://localhost:80` in your web browser to get a colorful message.
|
||||
```
|
||||
My New React App
|
||||
```
|
||||
|
||||
The backend service container has the port 80 mapped to 8080 on the host.
|
||||
```
|
||||
$ curl localhost:8080
|
||||
Hello Docker World
|
||||
```
|
||||
|
||||
Stop and remove the containers
|
||||
```
|
||||
$ docker-compose down
|
||||
Stopping react-express-mysql_frontend_1 ... done
|
||||
Stopping react-express-mysql_backend_1 ... done
|
||||
Stopping react-express-mysql_db_1 ... done
|
||||
Removing react-express-mysql_frontend_1 ... done
|
||||
Removing react-express-mysql_backend_1 ... done
|
||||
Removing react-express-mysql_db_1 ... done
|
||||
Removing network react-express-mysql_default
|
||||
|
||||
```
|
@ -1,12 +0,0 @@
|
||||
FROM node:10 as build
|
||||
|
||||
RUN mkdir /project
|
||||
WORKDIR /project
|
||||
COPY . .
|
||||
RUN yarn install
|
||||
RUN yarn run package
|
||||
|
||||
FROM nginx:1.13-alpine
|
||||
|
||||
COPY config/nginx.conf /etc/nginx/conf.d/default.conf
|
||||
COPY --from=build /project/dist /usr/share/nginx/html
|
@ -0,0 +1,80 @@
|
||||
## Compose sample application
|
||||
### React application with a NodeJS backend and a MySQL database
|
||||
|
||||
Project structure:
|
||||
```
|
||||
.
|
||||
├── backend
|
||||
│ ├── Dockerfile
|
||||
│ ...
|
||||
├── db
|
||||
│ └── password.txt
|
||||
├── docker-compose.yaml
|
||||
├── frontend
|
||||
│ ├── ...
|
||||
│ └── Dockerfile
|
||||
└── README.md
|
||||
```
|
||||
|
||||
[_docker-compose.yaml_](docker-compose.yaml)
|
||||
```
|
||||
services:
|
||||
backend:
|
||||
build: backend
|
||||
...
|
||||
db:
|
||||
image: mysql:5.7
|
||||
...
|
||||
frontend:
|
||||
build: frontend
|
||||
ports:
|
||||
- 80:9000
|
||||
...
|
||||
```
|
||||
The compose file defines an application with three services `frontend`, `backend` and `db`.
|
||||
When deploying the application, docker-compose maps port 80 of the frontend service container to port 9000 of the host as specified in the file.
|
||||
Make sure port 80 on the host is not already being in use.
|
||||
|
||||
## Deploy with docker-compose
|
||||
|
||||
```
|
||||
$ docker-compose up -d
|
||||
Creating network "react-java-mysql_default" with the default driver
|
||||
Building backend
|
||||
Step 1/10 : FROM maven:3.5-jdk-9 AS build
|
||||
...
|
||||
Successfully tagged react-java-mysql_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 react-java-mysql_frontend_1 ... done
|
||||
Creating react-java-mysql_db_1 ... done
|
||||
Creating react-java-mysql_backend_1 ... done
|
||||
```
|
||||
|
||||
## Expected result
|
||||
|
||||
Listing containers must show two containers running and the port mapping as below:
|
||||
```
|
||||
$ docker ps
|
||||
ONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||||
a63dee74d79e react-java-mysql_backend "java -Djava.securit…" 39 seconds ago Up 37 seconds react-java-mysql_backend_1
|
||||
6a7364c0812e react-java-mysql_frontend "docker-entrypoint.s…" 39 seconds ago Up 33 seconds 0.0.0.0:80->9000/tcp react-java-mysql_frontend_1
|
||||
b176b18fbec4 mysql:5.7 "docker-entrypoint.s…" 39 seconds ago Up 37 seconds 3306/tcp, 33060/tcp react-java-mysql_db_1
|
||||
e63be7db7cbc postgres "docker-entrypoint.s…" 2 hours ago Up 16 minutes 5432/tcp nginx-golang-postgres_db_1
|
||||
```
|
||||
|
||||
After the application starts, navigate to `http://localhost:80` in your web browser to get a colorful message.
|
||||
```
|
||||
My New React App
|
||||
```
|
||||
|
||||
Stop and remove the containers
|
||||
```
|
||||
$ docker-compose down
|
||||
Stopping react-java-mysql_backend_1 ... done
|
||||
Stopping react-java-mysql_frontend_1 ... done
|
||||
Stopping react-java-mysql_db_1 ... done
|
||||
Removing react-java-mysql_backend_1 ... done
|
||||
Removing react-java-mysql_frontend_1 ... done
|
||||
Removing react-java-mysql_db_1 ... done
|
||||
Removing network react-java-mysql_default
|
||||
```
|
@ -0,0 +1,70 @@
|
||||
## Compose sample application
|
||||
### Java Spark application with MySQL database
|
||||
|
||||
Project structure:
|
||||
```
|
||||
.
|
||||
├── backend
|
||||
│ ├── Dockerfile
|
||||
│ └── ...
|
||||
├── db
|
||||
│ └── password.txt
|
||||
├── docker-compose.yaml
|
||||
└── README.md
|
||||
|
||||
```
|
||||
|
||||
[_docker-compose.yaml_](docker-compose.yaml)
|
||||
```
|
||||
version: "3.7"
|
||||
services:
|
||||
backend:
|
||||
build: backend
|
||||
ports:
|
||||
- 80:8080
|
||||
db:
|
||||
image: mysql:5.7
|
||||
...
|
||||
```
|
||||
The compose file defines an application with two services `backend` and `db`.
|
||||
When deploying the application, docker-compose maps port 8080 of the backend service container to port 80 of the host as specified in the file.
|
||||
Make sure port 80 on the host is not already being in use.
|
||||
|
||||
## Deploy with docker-compose
|
||||
|
||||
```
|
||||
$ docker-compose up -d
|
||||
Creating network "sparkjava-mysql_default" with the default driver
|
||||
Building backend
|
||||
...
|
||||
Successfully tagged sparkjava-mysql_backend:latest
|
||||
WARNING: Image for service backend was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
|
||||
Creating sparkjava-mysql_db_1 ... done
|
||||
Creating sparkjava-mysql_backend_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
|
||||
ee1e4f05d9f6 sparkjava-mysql_backend "/bin/sh -c 'java -j…" 44 seconds ago Up 43 seconds 0.0.0.0:80->8080/tcp sparkjava-mysql_backend_1
|
||||
716025ddf65b mysql:5.7 "docker-entrypoint.s…" 44 seconds ago Up 43 seconds 3306/tcp, 33060/tcp sparkjava-mysql_db_1
|
||||
```
|
||||
|
||||
After the application starts, run:
|
||||
```
|
||||
$ curl localhost:80
|
||||
["Blog post #0","Blog post #1","Blog post #2","Blog post #3","Blog post #4"]
|
||||
```
|
||||
|
||||
Stop and remove the containers
|
||||
```
|
||||
$ docker-compose down
|
||||
Stopping sparkjava-mysql_backend_1 ... done
|
||||
Stopping sparkjava-mysql_db_1 ... done
|
||||
Removing sparkjava-mysql_backend_1 ... done
|
||||
Removing sparkjava-mysql_db_1 ... done
|
||||
Removing network sparkjava-mysql_default
|
||||
```
|
@ -0,0 +1,62 @@
|
||||
## Compose sample application
|
||||
### Spark Java
|
||||
|
||||
Project structure:
|
||||
```
|
||||
.
|
||||
├── docker-compose.yaml
|
||||
├── README.md
|
||||
└── sparkjava
|
||||
├── Dockerfile
|
||||
└── ...
|
||||
```
|
||||
|
||||
[_docker-compose.yaml_](docker-compose.yaml)
|
||||
```
|
||||
version: "3.7"
|
||||
services:
|
||||
sparkjava:
|
||||
build: sparkjava
|
||||
ports:
|
||||
- 80:8080
|
||||
```
|
||||
The compose file defines an application with one service `sparkjava`.
|
||||
When deploying the application, docker-compose maps port 8080 of the sparkjava service container to port 80 of the host as specified in the file.
|
||||
Make sure port 80 on the host is not already being in use.
|
||||
|
||||
## Deploy with docker-compose
|
||||
|
||||
```
|
||||
$ docker-compose up -d
|
||||
Creating network "sparkjava_default" with the default driver
|
||||
Building sparkjava
|
||||
Step 1/9 : FROM maven:3.5-jdk-8-alpine AS build
|
||||
3.5-jdk-8-alpine: Pulling from library/maven
|
||||
...
|
||||
Successfully tagged sparkjava_sparkjava:latest
|
||||
WARNING: Image for service sparkjava was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
|
||||
Creating sparkjava_sparkjava_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
|
||||
5af94cb25394 sparkjava_sparkjava "/bin/sh -c 'java -j…" 20 seconds ago Up 19 seconds 0.0.0.0:80->8080/tcp sparkjava_sparkjava_1
|
||||
```
|
||||
|
||||
After the application starts, navigate to `http://localhost:80` in your web browser or run:
|
||||
```
|
||||
$ curl localhost:80
|
||||
Hello world
|
||||
```
|
||||
|
||||
Stop and remove the containers
|
||||
```
|
||||
$ docker-compose down
|
||||
Stopping sparkjava_sparkjava_1 ... done
|
||||
Removing sparkjava_sparkjava_1 ... done
|
||||
Removing network sparkjava_default
|
||||
```
|
@ -0,0 +1,80 @@
|
||||
## Compose sample application
|
||||
### Java application with Spring framework and a Postgres database
|
||||
|
||||
Project structure:
|
||||
```
|
||||
.
|
||||
├── backend
|
||||
│ ├── Dockerfile
|
||||
│ └── ...
|
||||
├── db
|
||||
│ └── password.txt
|
||||
├── docker-compose.yaml
|
||||
└── README.md
|
||||
|
||||
```
|
||||
|
||||
[_docker-compose.yaml_](docker-compose.yaml)
|
||||
```
|
||||
version: "3.7"
|
||||
services:
|
||||
backend:
|
||||
build: backend
|
||||
ports:
|
||||
- 80:8080
|
||||
db:
|
||||
image: postgres
|
||||
...
|
||||
```
|
||||
The compose file defines an application with two services `backend` and `db`.
|
||||
When deploying the application, docker-compose maps port 8080 of the backend service container to port 80 of the host as specified in the file.
|
||||
Make sure port 80 on the host is not already being in use.
|
||||
|
||||
## Deploy with docker-compose
|
||||
|
||||
```
|
||||
$ docker-compose up -d
|
||||
Creating network "spring-postgres_default" with the default driver
|
||||
Building backend
|
||||
Step 1/11 : FROM maven:3.5-jdk-9 AS build
|
||||
3.5-jdk-9: Pulling from library/maven
|
||||
...
|
||||
Successfully tagged spring-postgres_backend:latest
|
||||
WARNING: Image for service backend was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
|
||||
Creating spring-postgres_backend_1 ... done
|
||||
Creating spring-postgres_db_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
|
||||
56236f640eaa postgres "docker-entrypoint.s…" 29 seconds ago Up 28 seconds 5432/tcp spring-postgres_db_1
|
||||
6e69472dc2c0 spring-postgres_backend "java -Djava.securit…" 29 seconds ago Up 28 seconds 0.0.0.0:80->8080/tcp spring-postgres_backend_1
|
||||
```
|
||||
|
||||
After the application starts, navigate to `http://localhost:80` in your web browse or run:
|
||||
```
|
||||
$ curl localhost:80
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Getting Started: Serving Web Content</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
</head>
|
||||
<body>
|
||||
<p>Hello from Docker!</p>
|
||||
</body>
|
||||
```
|
||||
|
||||
Stop and remove the containers
|
||||
```
|
||||
$ docker-compose down
|
||||
Stopping spring-postgres_db_1 ... done
|
||||
Stopping spring-postgres_backend_1 ... done
|
||||
Removing spring-postgres_db_1 ... done
|
||||
Removing spring-postgres_backend_1 ... done
|
||||
Removing network spring-postgres_default
|
||||
```
|
@ -0,0 +1,62 @@
|
||||
## Compose sample application
|
||||
### VueJS
|
||||
|
||||
Project structure:
|
||||
```
|
||||
.
|
||||
├── docker-compose.yaml
|
||||
├── README.md
|
||||
└── vuejs
|
||||
├── Dockerfile
|
||||
└── ...
|
||||
```
|
||||
|
||||
[_docker-compose.yaml_](docker-compose.yaml)
|
||||
```
|
||||
version: "3.7"
|
||||
services:
|
||||
web:
|
||||
build: vuejs
|
||||
ports:
|
||||
- 80:8080
|
||||
volumes:
|
||||
- ./vuejs:/project
|
||||
- /project/node_modules
|
||||
```
|
||||
The compose file defines an application with one service `sparkjava`.
|
||||
When deploying the application, docker-compose maps port 8080 of the web service container to port 80 of the host as specified in the file.
|
||||
Make sure port 80 on the host is not already being in use.
|
||||
|
||||
## Deploy with docker-compose
|
||||
|
||||
```
|
||||
$ docker-compose up -d
|
||||
Creating network "vuejs_default" with the default driver
|
||||
Building web
|
||||
Step 1/8 : FROM node:10
|
||||
...
|
||||
Successfully tagged vuejs_web:latest
|
||||
WARNING: Image for service web was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
|
||||
Creating vuejs_web_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
|
||||
701c02bb97b1 vuejs_web "docker-entrypoint.s…" 49 seconds ago Up 46 seconds 0.0.0.0:80->8080/tcp vuejs_web_1
|
||||
```
|
||||
|
||||
After the application starts, navigate to `http://localhost:80` in your web browser.
|
||||
|
||||
![page](output.jpg)
|
||||
|
||||
Stop and remove the containers
|
||||
```
|
||||
$ docker-compose down
|
||||
Stopping vuejs_web_1 ... done
|
||||
Removing vuejs_web_1 ... done
|
||||
Removing network vuejs_default
|
||||
```
|
Binary file not shown.
After Width: | Height: | Size: 48 KiB |
Binary file not shown.
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 3.5 KiB |
Binary file not shown.
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 38 KiB |
Loading…
Reference in New Issue