Added Dockerfile (#73)

* Added Dockerfile

* Docker brought back to root

* Updated Dockerfile, node version and ENTRYPOINT usage

* Added .dockerignore

* Alpine image docker

* Change suggested image name

* Add note about podman
This commit is contained in:
Anjan Nair 2022-07-15 03:25:34 +05:30 committed by GitHub
parent 0950d1a385
commit e2481cbc7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 150 additions and 0 deletions

131
.dockerignore Normal file
View File

@ -0,0 +1,131 @@
# Git
.git
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
.env.production
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
# db files
.db
playerdata.db
# ssl keys
*.pem
# origin sid cookie
sid.cookie

6
Dockerfile Normal file
View File

@ -0,0 +1,6 @@
FROM node:16.15.0-alpine
WORKDIR /app
COPY package.json /app
RUN npm install && mv /app/node_modules /node_modules
COPY . /app
ENTRYPOINT ["npm", "run", "--"]

View File

@ -5,3 +5,16 @@ The master server is responsible for centralizing game servers created by player
### Format
This project uses `eslint` to format code, make sure you run `eslint --fix .` before opening a Pull Request.
## Using With Docker
1) Build your image - `docker build -t northstarmasterserver .`
2) Run it in a container using the following code -`docker run -it -p 8080:80 -v $(pwd):/app northstarmasterserver <script>`
A little explanation of the run command arguments -
1. `-it` - Interactive mode, optionally you can use `-d` to run it in detached mode
2. `-p 8080:80` - While debugging using Docker port 80 is not allowed for obvious reasons hence we expose the container's port 80 to the host's port 8080
3. `-v $(pwd):/app` - It maps a virtual directory from the host machine (`$(pwd)`) to the specified folder in the Docker image (`/app`), meaning that the docker image sees the contents of the hosts directory in runtime (on-the-fly) without having to rebuild the image
4. `northstarmasterserver` - The image tag name as mentioned when building it
5. `<script>` - This should be replaced by any one scripts such as **start**, **watch** etc from *package.json*
Alternatively the above commands can also be used as-is with `podman`.