https://github.com/rifandani/dicoding-azure-submission-2-backend
Dicoding azure submission 2 backend
https://github.com/rifandani/dicoding-azure-submission-2-backend
Last synced: 7 months ago
JSON representation
Dicoding azure submission 2 backend
- Host: GitHub
- URL: https://github.com/rifandani/dicoding-azure-submission-2-backend
- Owner: rifandani
- Created: 2021-03-18T16:59:23.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-18T16:59:49.000Z (over 4 years ago)
- Last Synced: 2025-01-21T15:49:14.359Z (9 months ago)
- Language: TypeScript
- Size: 164 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Node.js with Docker
> from [Nodejs official website](https://nodejs.org/en/docs/guides/nodejs-docker-webapp/)
## Building your image
Go to the directory that has your `Dockerfile` and run the following command to build the Docker image.
The `-t` flag lets you tag your image so it's easier to find later using the docker images command:```bash
docker build -t /node-web-app .
```Your image will now be listed by Docker:
```bash
$ docker imagesREPOSITORY TAG ID CREATED
node 14 1934b0b038d1 5 days ago
/node-web-app latest d64d3505b0d2 1 minute ago
```## Run the image
Running your image with `-d` runs the container in detached mode, leaving the container running in the background.
The `-p` flag redirects a public port to a private port inside the container. Run the image you previously built:```bash
docker run -p 49160:8080 -d /node-web-app
```Print the output of your app:
```bash
# Get container ID
$ docker ps# Print app output
$ docker logs# Example
Running on http://localhost:8080
```If you need to go inside the container you can use the `exec` command:
```bash
# Enter the container
$ docker exec -it /bin/bash
```## Test
To test your app, get the port of your app that Docker mapped:
```bash
$ docker ps# Example
ID IMAGE COMMAND ... PORTS
ecce33b30ebf /node-web-app:latest npm start ... 49160->8080
```In the example above, Docker mapped the `8080` port inside of the container to the port `49160` on your machine.
Now you can call your app using `curl` (install if needed via: `sudo apt-get install curl`):
```bash
$ curl -i localhost:49160HTTP/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-aliveHello world
```