docusaurus/docs/getting-started-docker.md

64 lines
2.4 KiB
Markdown
Raw Normal View History

2018-09-01 05:06:56 -04:00
---
id: docker
title: Docker
---
2018-09-05 13:56:19 -04:00
[Docker](https://www.docker.com/) is a tool that enables you to create, deploy, and manage lightweight, stand-alone packages that contain everything needed to run an application. It can help us to avoid conflicting dependencies & unwanted behavior when running Docusaurus.
2018-09-01 05:06:56 -04:00
## Run the local web server in docker
2018-09-01 05:06:56 -04:00
2018-09-06 14:13:13 -04:00
Ensure you have previously installed [docker](https://www.docker.com/get-started).
2018-09-01 05:06:56 -04:00
To run the local web server:
2018-09-01 05:06:56 -04:00
2018-09-06 14:13:13 -04:00
1. **Build the docker image** -- Enter the folder where you have Docusaurus installed. Run `docker build -t docusaurus-doc .`
2018-09-01 05:06:56 -04:00
Once the build phase finishes, you can verify the image exists by running `docker images`.
2018-09-01 05:06:56 -04:00
> We now include a `Dockerfile` when you install Docusaurus.
2018-09-01 05:06:56 -04:00
2018-09-06 14:13:13 -04:00
2. **Run the Docusaurus container** -- To start docker run `docker run --rm -p 3000:3000 docusaurus-doc`
2018-09-01 05:06:56 -04:00
This will start a docker container with the image `docusaurus-doc`. To see more detailed container info run `docker ps` .
2018-09-01 05:06:56 -04:00
2018-09-06 14:13:13 -04:00
## Use docker-compose
2018-09-01 05:06:56 -04:00
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.
2018-09-06 14:13:13 -04:00
> Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your applications services. Then, with a single command, you create and start all the services from your configuration.
Using Compose is a three-step process:
2018-09-01 05:06:56 -04:00
1. Define your apps environment with a Dockerfile so it can be reproduced anywhere.
2018-09-06 14:13:13 -04:00
2. Define the services that make up your app in `docker-compose.yml` so they can be run together in an isolated environment.
2018-09-01 05:06:56 -04:00
2018-09-06 14:13:13 -04:00
3. Run `docker-compose up` and Compose starts and runs your entire app.
2018-09-01 05:06:56 -04:00
2018-09-06 14:13:13 -04:00
We include a basic `docker-compose.yml` in your project:
```yml
version: '3'
2018-09-01 05:06:56 -04:00
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`.
2018-09-01 05:06:56 -04:00
2018-09-06 14:13:13 -04:00
To build static HTML pages for publishing run `docker-compose run docusaurus bash -c 'yarn publish-gh-pages'`