Giter VIP home page Giter VIP logo

reactjs_study_docker's Introduction

Dockerized App

An educational React app exploring Docker containerization. Utilized Docker Compose to manage development and production environments.

Tech Stack

Client:

Requirements

Run Locally

Clone the project

  git clone https://github.com/Anathangv/reactjs_study_docker.git

Go to the project directory

  cd reactjs_study_docker

Install dependencies

  npm install

Start the application development mode

  docker-compose -f docker-compose.dev.yml up

  #or run in detached mode
  docker-compose -f docker-compose.dev.yml up -d

Open the URL in the browser: http://localhost:3000/

Start the application production mode

  docker-compose up

  #or run in detached mode
  docker-compose up -d

Open the URL in the browser: http://localhost:8080/

Documentation

  • Additional details and insights can be found within the code comments provided in certain sections
  • In the project directory add .dockerignore file
  node_modules
  • Create a Dockerfile
  # Stage 0 - Development
  FROM node:16.16-alpine AS development
  WORKDIR /app 
  COPY package*.json ./
  RUN npm install
  COPY . .
  EXPOSE 3000
  CMD [ "npm", "run", "dev" ]


  # Stage 0 - "Production"
  FROM node:16.16-alpine as build
  WORKDIR /app 
  COPY package*.json ./
  RUN npm install
  COPY . .
  RUN npm run build

  # Stage 1 - "Production"
  FROM nginx:1.25.3-alpine3.18 as production
  COPY --from=build /app/dist/ /usr/share/nginx/html
  COPY --from=build /app/nginx/nginx.conf /etc/nginx/conf.d/default.conf
  EXPOSE 80
  CMD ["nginx", "-g", "daemon off;"]
  • Create the file nginx.conf within the new folder called nginx
  server {
      listen 80;
      location / {
          root /usr/share/nginx/html;
          index index.html index.htm;
          try_files $uri $uri/ /index.html =404;
      }
  }
  • Create the docker-compose.dev.yml file for development environment
  version: "3.8"
  services:
    app:
      container_name: app-dev
      image: app-dev
      build:
        context: .
        target: development
      volumes:
        - ./src:/app/src
      ports:
        - 3000:3000
  • When using Vite, it's necessary to modify the 'vite.config.ts' file to ensure that the application functions correctly in the web browser
  export default defineConfig({
    plugins: [react()],
    server: {
      host: true,
      port: 3000, // This is the port which we will use in docker
      watch: {
        usePolling: true
      } 
    }
  })
  • Create the docker-compose.yml file for production environment
  version: "3.8"
  services:
    nginx-react:
      container_name: my-docker-app-container
      image: my-docker-app
      build:
        context: .
        dockerfile: Dockerfile
      ports:
        - 8080:80

Screenshots

Development:

image

Production:

image

Docker Desktop - Images:

image

reactjs_study_docker's People

Contributors

anathangv 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.