Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/softchris/node-api-sequelize
example of an API using sqlite, sequelize, docker
https://github.com/softchris/node-api-sequelize
Last synced: 16 days ago
JSON representation
example of an API using sqlite, sequelize, docker
- Host: GitHub
- URL: https://github.com/softchris/node-api-sequelize
- Owner: softchris
- Created: 2018-10-27T00:03:14.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-09T05:53:55.000Z (almost 2 years ago)
- Last Synced: 2024-10-07T13:22:04.741Z (about 1 month ago)
- Language: JavaScript
- Size: 128 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Dockerfile
This is a file called `Dockerfile` which allows us to specify how to build a container. Let's have a look at one:
```
FROM
```This means we pull down an image that we base this on, this is usually an image that is based on an OS like Ubuntu for example. Let's take an image where nodejs is pre installed, like so:
```
FROM node:8
```Now let's set a working directory for our app. This is where all the files will be placed. It's done with the `WORKDIR` command:
```
WORKDIR /usr/src/app
```Next step is copying over the `package.json` file as it contains instructions for what NPM modules our app needs, like so:
```
COPY package*.json ./
```After that we need to actually install the libraries like so:
```
RUN npm install
```Now let's copy the entire app. We want all the files to end up in our work directory so we write:
```
COPY . .
```from current directory into `WORKDIR`
Now let's expose a port in which you can find our application:
```
EXPOSE 8080
```Lastly start up our app by calling
```
CMD ["npm", "start"]
```Let's show the `Dockerfile` in its entirety:
```
FROM node:8
WORKDIR /usr/src/appCOPY package*.json ./
RUN npm install
# Bundle app source
COPY . .EXPOSE 8080
CMD [ "npm ", "start" ]
```# build
Next step is to build our `Dockerfile` and create an image. Once we have an image we can start a container from it. For that we will use the `docker build` command, like so:
```
docker build -t /node-web-app .
```We use the `-t` to tag, give it a name. Let's inspect by running
```
docker images
```This should list our image with the name we tagged it with.
# run
Now let's create a container from our image so we can actually is ut for something. We do that with the following command:
```
docker run -p 49160:8080 -d /node-web-app
```Let's break apart this a bit `-p` means that we are creating a bridge between our host OS and our container. What we are saying is which port on our container should connect to what port in the container. The syntax looks like this:
```
-p :
```By typing
```
-p 49160:8080
```We are saying we can find the app running at `http://localhost:49160`
OR we can use `curl`, like so:```
curl -i localhost:49160
```We have already said in `app.js` that we aim to run our express server on port 8080 and expose the same port in the `Dockerfile`