Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Docker file for the projects #10

Merged
merged 14 commits into from
May 10, 2021
5 changes: 5 additions & 0 deletions Docker_Container/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
build
.dockerignore
Dockerfile
Dockerfile.prod
54 changes: 54 additions & 0 deletions Docker_Container/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
## Steps to start the build with Docker
yasharth291 marked this conversation as resolved.
Show resolved Hide resolved

### Project Setup

yasharth291 marked this conversation as resolved.
Show resolved Hide resolved
- Install [Docker](https://www.docker.com/)

- Build and Tag The Docker Image

``$ docker build -t sample:dev``
yasharth291 marked this conversation as resolved.
Show resolved Hide resolved

- Then Spin up the container once build is done

```
$ docker run \
-it \
--rm \
-v ${PWD}:/app \
-v /app/node_modules \
-p 3001:3000 \
-e CHOKIDAR_USEPOLLING=true \
sample:dev
```

- Whats Happening here

1. The ``docker run`` command creates and runs a new conatiner instance from the image we just created

2. ``-it`` starts the container in interactive mode

3. ``--rm`` removes the container and volumes after the container exists.

4. ``-v ${PWD}:/app`` mounts the code into the container at "/app".

5. Since we want to use the container version of the “node_modules” folder, we configured another volume: ``-v /app/node_modules`` . You should now be able to remove the local “node_modules” flavor.

6. ``-p 3001:3000`` exposes port 3000 to other Docker containers on the same network (for inter-container communication) and port 3001 to the host.

7. Finally , ``-e CHOKIDAR_USEPOLLING=true`` enables a polling mechanism via chokidar (which wraps ``fs.watch``, ``fs.watchFile``, and ``fsevents``) so that hot-reloading will work.

### For using compose file

- Build the image and fire up the container

`` $ docker-compose up -d --build ``

- Ensure the app is running in the browser and test hot - reloading again. Bring down the container before moving on

``$ docker-compose stop``

- Now your container is ready to run

yasharth291 marked this conversation as resolved.
Show resolved Hide resolved



16 changes: 16 additions & 0 deletions Docker_Container/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3.7'

services:

sample:
container_name: sample
build:
context: .
dockerfile: Dockerfile
volumes:
- '.:/app'
- '/app/node_modules'
ports:
- 3001:3000
environment:
- CHOKIDAR_USEPOLLING=true
21 changes: 21 additions & 0 deletions Docker_Container/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# pull official base image
FROM node:13.12.0-alpine

# set working directory
WORKDIR /app

# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH

# install app dependencies
COPY package.json ./
COPY yarn.lock ./
COPY package-lock.json ./
yasharth291 marked this conversation as resolved.
Show resolved Hide resolved
RUN yarn install --silent
RUN yarn install [email protected] -g --silent

# add app
COPY . ./

# start app
CMD ["yarn", "start"]
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,6 @@ yarn lint
See [Configuration Reference](https://cli.vuejs.org/config/).


## Project setup using docker

See [Docker Container](Docker_Container\README.md)