add docker doc
parent
71b3251a25
commit
4bd1988153
@ -0,0 +1,91 @@
|
||||
# Build Docker image
|
||||
|
||||
* [Reference](https://nodejs.org/en/docs/guides/nodejs-docker-webapp/)
|
||||
|
||||
* Command
|
||||
|
||||
```bash
|
||||
// run with interactive shell
|
||||
$ docker run -it <image> /bin/bash
|
||||
|
||||
// list running process
|
||||
$ docker ps
|
||||
|
||||
// list images
|
||||
$ docker images
|
||||
|
||||
//
|
||||
$ docker exec -it <container id> /bin/bash
|
||||
|
||||
// print app output
|
||||
$ docker logs <container id>
|
||||
|
||||
// build docker image. image name cannot use camel case
|
||||
$ docker build -t <target-image-name> .
|
||||
|
||||
// store image in tart file
|
||||
$ docker save <generated-image-name> -o ./store/<generated-image-name>.tar
|
||||
|
||||
// upload tar image to server
|
||||
$ rsync -rzvP ./store/<generated-image-name>.tar ubuntu@<serverip>:~/apps/<image-name>/
|
||||
|
||||
$ ssh ubuntu@<serverip>
|
||||
$ cd ~/apps/<image-name>
|
||||
$ docker-compose stop
|
||||
$ docker load -i <image-name>.tar
|
||||
$ docker-compose up -d --build
|
||||
```
|
||||
|
||||
|
||||
|
||||
* testing http
|
||||
|
||||
```bash
|
||||
$ curl -i localhost:5000
|
||||
|
||||
HTTP/1.1 200 OK
|
||||
X-Powered-By: Express
|
||||
Content-Type: text/html; charset=utf-8
|
||||
Content-Length: 12
|
||||
ETag: W/"c-M6tWOb/Y57lesdjQuHeB1P/qTV0"
|
||||
Date: Mon, 13 Nov 2017 20:53:59 GMT
|
||||
Connection: keep-alive
|
||||
|
||||
Hello world
|
||||
```
|
||||
|
||||
|
||||
|
||||
* sample deploy script
|
||||
|
||||
```bash
|
||||
# docker way
|
||||
docker build -t razer-pay-direct-fast-middleware:latest .
|
||||
docker save razer-pay-direct-fast-middleware:latest -o ./docker-local/razer-pay-direct-fast-middleware.tar
|
||||
|
||||
# upload docker image and compose file to the server
|
||||
rsync -rzvP ./docker-local/razer-pay-direct-fast-middleware.tar docker-compose.yml ubuntu@172.88.1.101:~/apps/razer-pay-direct-fast-middleware/
|
||||
|
||||
ssh ubuntu@172.88.1.101 << EOF
|
||||
cd ~/apps/razer-pay-direct-fast-middleware
|
||||
pwd
|
||||
|
||||
echo "Stopping Container..."
|
||||
docker-compose stop
|
||||
|
||||
echo "Loading new Docker image..."
|
||||
docker load -i razer-pay-direct-fast-middleware.tar
|
||||
|
||||
echo "Restarting Container..."
|
||||
docker-compose up -d --build
|
||||
|
||||
echo "Container restarted."
|
||||
|
||||
EOF
|
||||
|
||||
echo "Deployed successfully."
|
||||
```
|
||||
|
||||
|
||||
|
||||
* s
|
||||
Loading…
Reference in New Issue