Hosting Nodejs App using your own Docker Image in Jelastic PaaS/ Yeti Cloud

Intro Image

Step 1: Setup a nodejs application

You need to setup a node js project or use your existing node js project.

Step 2: Setup Dockerfile

  • Create a file name Dockerfile and .dockerignore in the root of your project.
  • In .dockerignore add files that need to be ignored like .env, node_modules
FROM node:14 as dependencies # Use node:14 image as base and name or tag it as dependencies# Create app directory
WORKDIR /root/ROOT # Specify the folder where project lies, it will be created for you if not exists
COPY package.json ./ # Copy a package.json file to the container
RUN npm install # Install dependency from package.json
FROM node:14 as runner # Use node:14 image as base and name or tag it as runner
WORKDIR /root/ROOT # Specify the folder where project lies, it will be created for you if not exists
COPY . . # Copy all the files anf folder from project to container
COPY --from=dependencies /root/ROOT/node_modules ./node_modules # Copy node module we have installed in dependencies
ENV NODE_ENV production #SET ENV VARIABLES
ENV PORT 3000
EXPOSE 3000
# Expose port so that outside world can acces the port of container
RUN chmod +x entrypoint.sh # Make script file readable if available otherwise remove these two lines
ENTRYPOINT ["./entrypoint.sh"] # Script File if something need to be done before application starts like database migration
CMD ["npm","start"] # Start Application Command

Step 3: Build Dockerfile

  • You need to install docker on your local machine to follow these steps
  • To build Docker Image we run command from root of the project
docker build -t tag-name . 
  • If error occurs during build fix error and build again

Step 4: Push Docker Image

You need to create a docker hub account or use other services like AWS ECR for these steps.

docker login # It will ask username and passworddocker push your-username/image_name

Step 5: Into Jelastic Dashboard

  • Goto Dashboard -> Click New Environment
  • Goto Custom
Create Enviroment Custom
  • Click Select Image
Select Custom Container
  • Click Add New Image
Add Docker Image
  • Enter your image-name or url, username and password of docker hub or any other repository you are using
  • Click Add
Select Docker Image

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store