diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..612a465 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +# Stage 1: Base image. +FROM node:lts as base +## Disable colour output from yarn to make logs easier to read. +ENV FORCE_COLOR=0 +## Enable corepack. +RUN corepack enable +## Set the working directory to `/opt/docusaurus`. +WORKDIR /opt/docusaurus + +# Stage 2a: Development mode. +FROM base as dev +## Set the working directory to `/opt/docusaurus`. +WORKDIR /opt/docusaurus +## Expose the port that Docusaurus will run on. +EXPOSE 3000 +## Run the development server. +CMD [ -d "node_modules" ] && npm run start --host 0.0.0.0 --poll 1000 || npm run install && npm run start --host 0.0.0.0 --poll 1000 + +# Stage 2b: Production build mode. +FROM base as prod +## Set the working directory to `/opt/docusaurus`. +WORKDIR /opt/docusaurus +## Copy over the source code. +COPY . /opt/docusaurus/ +## Install dependencies with `--immutable` to ensure reproducibility. +RUN npm ci +## Build the static site. +RUN npm run build + +# Stage 3a: Serve with `docusaurus serve`. +FROM prod as serve +## Expose the port that Docusaurus will run on. +EXPOSE 3000 +## Run the production server. +CMD ["npm", "run", "serve", "--", "--host", "0.0.0.0", "--no-open"] + +# Stage 3b: Serve with Caddy. +FROM caddy:2-alpine as caddy +## Copy the Caddyfile. +COPY --from=prod /opt/docusaurus/Caddyfile /etc/caddy/Caddyfile +## Copy the Docusaurus build output. +COPY --from=prod /opt/docusaurus/build /var/docusaurus \ No newline at end of file diff --git a/README.md b/README.md index eec2263..65a5283 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,36 @@ We would love to be your first PR! or any PR for that matter. Take a look at our If you have ideas for updating the guide content, please open a PR and we would take a look at it. +## Docker Support + +You can pull the public image from docker hub [rishabkumar7/ltc-website](https://hub.docker.com/r/rishabkumar7/ltc-website) or build it locally. + +### Building the Docker Image: + +To build the docker image you will need to run the following command: + +``` bash +docker build --target -t . +``` + +- `--target ` - This is the target to build. The target is the name of the stage in the dockerfile. Valid targets are `dev`, `serve` and `caddy` +- `-t ` - This is the name and tag of the image that will be built. The format is :. The name can be anything you want. The tag is optional. If you do not specify a tag, latest will be used. + +- `.` - This is the path to the build context. In this case we are using the current directory (root directory of this project) as the build context. + +### Running the Docker Image + +To run the serve target you will need to run the following command: + +``` bash +docker run --rm -d -p 3000:3000 +``` + +- `--rm` - This is an optional flag that will remove the container when it exits. +- `-d` - This is an optional flag that will run the container in detached mode. +- `-p 3000:3000` - This is an optional flag that will map port 3000 on the host to port 3000 in the container. +- `` - This is the name and tag of the image that will be run. Make sure to use the same tag that you used when building the image. + ## License Distributed under the MIT License. See [LICENSE](/LICENSE) for more information. diff --git a/package.json b/package.json index 4eedc72..dd57c29 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "docusaurus": "docusaurus", - "start": "docusaurus start", + "start": "docusaurus start --host 0.0.0.0", "build": "docusaurus build", "swizzle": "docusaurus swizzle", "deploy": "docusaurus deploy",