Skip to content

Commit

Permalink
Merge pull request #203 from learntocloud/docker-image
Browse files Browse the repository at this point in the history
Added Docker support for LTC website
  • Loading branch information
rishabkumar7 authored May 28, 2024
2 parents 145ee98 + ecef173 commit 73b1c22
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
42 changes: 42 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <target> -t <tag> .
```

- `--target <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 <tag>` - This is the name and tag of the image that will be built. The format is <name>:<tag>. 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 <tag>
```

- `--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.
- `<tag>` - 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.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 73b1c22

Please sign in to comment.