Create folder
mkdir tmp-folder
cd tmp-folder
Create file Dockerfile
FROM node:9.5.0-slim
LABEL manteiner="[email protected]"
# Install YARN
RUN apt-get update && apt-get install -y curl apt-transport-https && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && apt-get install -y yarn
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
VOLUME /usr/src/app
COPY . .
Create file `docker-compose.yml
version: '3'
services:
app:
container_name: app-react-electron
image: app-react-electron
build: .
command: yarn start
environment:
- PORT=3001
- NODE_ENV=dev
- ENV_NAME=local
- NODE_PATH=src/
ports:
- "3001:3001"
volumes:
- .:/usr/src/app
Run terminal commands:
~> docker-compose run --rm app yarn create react-app app
~> sudo chown -R $USER:$USER .
~> mv Dockerfile app/
~> mv docker-compose.yml app/
~> cd app
~> docker-compose run --rm app yarn eject
~> docker-compose run --rm app yarn add babel-loader
Now change the Dockerfile
FROM node:9.5.0-slim
LABEL manteiner="[email protected]"
# Install YARN
RUN apt-get update && apt-get install -y curl apt-transport-https && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && apt-get install -y yarn
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
VOLUME /usr/src/app
COPY . .
RUN yarn install
EXPOSE 3001
Create file dev-start.sh
#!/usr/bin/env bash
# Forces running containers to stop.
docker-compose kill
# Forcefully removes any stopped service containers.
docker-compose rm -f
# Runs the app with port(s) enabled and mapped to the host. Removes the container after run.
docker-compose run --rm --service-ports app
Add permission to exec file:
chmod +x dev-start.sh
Run ./dev-start.sh
and open link http://localhost:3001 with the browser .