Code Monkey home page Code Monkey logo

how-to-write-dockerfile's Introduction

Dockerfile

  • Stage 1 uses node:lts-alpine as its base and uses builder as the stage name.
  • On line 5, we install python, make, and g++. The node-gyp tool requries these three packages to run.
  • On line 7, we set /app directory as the WORKDIR.
  • On line 9 and 10, we copy the package.json file to the WORKDIR and install dependencies
  • Stage 2 also uses node-lts:alpine as the base.
  • On line 16, we set the NODE_ENV environment variable to production. This is important for the API to run properly.
  • From line 18 to line 20, we set the default user to node, create the /home/node/app directory, and set that as the WORKDIR.
  • On line 22, we copy all the project files and on line 23 we copy the node_modules directory from the builder stage. This directory contains all the built dependencies necessary for running the application.
  • On line 25, we set the default command.

Attach volume and network bridge

Once notes-db container is running, uses the notes-db-data volume, and is attached to the notes-api-network bridge.

docker container run \
  --detach \
  --name=notes-api \
  --env DB_HOST=notes-db \
  --env DB_DATABASE=notesdb \
  --env DB_PASSWORD=secret \
  --publish=3000:3000 \
  --network=notes-api-network \
  notes-api

The notes-api application requires three environment variables to be set.

  • DB_HOST - This is the host of the database server. Given that both the database server and the API are attached to the same user-defined bridge network, the database server can be referred to using its container name which is notes-db in this case.
  • DB_DATABASE - The database that is API will use. On Running the database server we set the default database name to notesdb using the POSTGRES_DB environment variable. We'll use that here.
  • DB_PASSWORD - Password for connecting to the database. This was also set on running the database server sub-section using the POSTGRES_PASSWORD environment variable.

how-to-write-dockerfile's People

Contributors

nayabatir1 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.