Docker
Docker 是一个可以让你创建、部署和管理轻量化、独立包的工具,他包含了应用运行所有的依赖。 当运行Docusaurus的时候,它可以帮助我们避免依赖冲突和一些异常行为。
用 Docker 本地运行服务
在这之前确保你已经安装了Docker。
准备运行本地服务:
Build the docker image -- Enter the folder where you have Docusaurus installed. 运行
docker build -t docusaurus-doc .
当构建镜像的阶段结束的时候,你可以通过
docker images
来验证时候构建成功。当你安装Docusaurus的时候我们已经有一个
Dockerfile
了。Run the Docusaurus container -- To start docker run
docker run --rm -p 3000:3000 docusaurus-doc
这将运行一个镜像为
docusaurus-doc
的Docker容器。 想看更详细的容器信息运行docker ps
To access Docusaurus from outside the docker container you must add the --host
flag to the docusaurus-start
command as described in: API Commands
使用 docker-compose
We can also use docker-compose
to configure our application. This feature of docker allows you to run the web server and any additional services with a single command.
Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.
Using Compose is a three-step process:
Define your app’s environment with a Dockerfile so it can be reproduced anywhere.
Define the services that make up your app in
docker-compose.yml
so they can be run together in an isolated environment.Run
docker-compose up
and Compose starts and runs your entire app.
我们在您的项目中包含一个基本的 docker-compose.yml
version: '3'
services:
docusaurus:
build: .
ports:
- 3000:3000
- 35729:35729
volumes:
- ./docs:/app/docs
- ./website/blog:/app/website/blog
- ./website/core:/app/website/core
- ./website/i18n:/app/website/i18n
- ./website/pages:/app/website/pages
- ./website/static:/app/website/static
- ./website/sidebars.json:/app/website/sidebars.json
- ./website/siteConfig.js:/app/website/siteConfig.js
working_dir: /app/website
To run a local web server with docker-compose
run docker-compose up
.
To build static HTML pages for publishing run docker-compose run docusaurus bash -c 'yarn publish-gh-pages'