Unit 3 Chapter 2: Official Docusaurus Tutorial Part 2
In this chapter, you will run the app you created in the previous chapter. In the previous chapter, you used the "docker run" command to start Docker. When you created the Docusaurus app with the "docusaurus-init" command, it automatically provided a Dockerfile and docker-compose.yml file in the new app. In this chapter, you will make use of the Dockerfile and docker-compose.yml file to set up Docker and run the app.
Topics Covered
- Docker-Compose
Ownership By Root
Please note that the Docusaurus app you created is owned by root in not only the Docker environment but in your host environment as well. While it's easy to change ownership of files from root to that of your regular username, I disagree with this practice and will show you my way of doing things in later chapters.
Starting the Docker Container
- In a shell terminal, enter the following commands:
cd
mkdir -p docker-docu
cd docker-docu
cd docusaurus-tutorial
docker-compose build
- It will take a few minutes to set up the Docker container and build the tutorial app. When the process is finished, the screen output should look something like this:
Building docusaurus
Step 1/7 : FROM node:lts
lts: Pulling from library/node
81fc19181915: Pull complete
ee49ee6a23d1: Pull complete
828510924538: Pull complete
a8f58c4fcca0: Pull complete
33699d7df21e: Pull complete
923705ffa8f8: Pull complete
c214b6cd5b8c: Pull complete
4c73d8285dba: Pull complete
1c58ef740d94: Pull complete
Digest: sha256:1e17e0fdecf65b7b86e50875ad5f11ae181a8d0351806babd61b332bc32a2c15
Status: Downloaded newer image for node:lts
---> 1fa6026dd8bb
Step 2/7 : WORKDIR /app/website
---> Running in 8fc01144407e
Removing intermediate container 8fc01144407e
---> 6a383b09efcd
Step 3/7 : EXPOSE 3000 35729
---> Running in 2816ccd60e6a
Removing intermediate container 2816ccd60e6a
---> 8feb84e2b778
Step 4/7 : COPY ./docs /app/docs
---> 50f23f16741c
Step 5/7 : COPY ./website /app/website
---> 7f5125537378
Step 6/7 : RUN yarn install
---> Running in c515131bd485
yarn install v1.22.4
warning package.json: No license field
warning No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.13: The platform "linux" is incompatible with this module.
info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 32.21s.
Removing intermediate container c515131bd485
---> f090259600f5
Step 7/7 : CMD ["yarn", "start"]
---> Running in 614846db0d70
Removing intermediate container 614846db0d70
---> b0b5b650561e
Successfully built b0b5b650561e
Successfully tagged docusaurus-tutorial_docusaurus:latest
- When the build process is finished, note that the shell prompt is in the host environment instead of Docker.
- Enter the command
docker ps -a
. The list of Docker containers should be blank. Note that the build process removed the Docker containers once they were no longer needed to execute commands. - Enter the command
docker images -a
. The screen output should look something like this:
REPOSITORY TAG IMAGE ID CREATED SIZE
docusaurus-tutorial_docusaurus latest b0b5b650561e 3 minutes ago 1.07GB
<none> <none> f090259600f5 3 minutes ago 1.07GB
<none> <none> 8feb84e2b778 4 minutes ago 918MB
<none> <none> 50f23f16741c 4 minutes ago 918MB
<none> <none> 7f5125537378 4 minutes ago 919MB
<none> <none> 6a383b09efcd 4 minutes ago 918MB
node lts 1fa6026dd8bb 2 days ago 918MB
- The Docker image with the name "node" is the original one specified as the base image in the Dockerfile. Each of the images with "none" in the name are the intermediate steps specified in the Dockerfile. The "docusaurus-tutorial_docusaurus" Docker image is the final result from the Dockerfile.
Viewing the Tutorial App
- Enter the command
docker-compose up
to start the Docusaurus server. In a few seconds, the Docusaurus app will be up and running locally. - Open your web browser, and go to the URL http://localhost:3000/ on your host system. Once again, your new Docusaurus app should appear.
- Open your web browser and go to the URL http://localhost:35729/ on your host sytem. Once again, you're looking at the output of the LiveReload server, and you'll see something similar to this:
{"tinylr":"Welcome","version":"1.1.1"}
- Start a new terminal tab for running commands in the host environment. (Remember, the original terminal tab is dedicated to running the Docusaurus app server and LiveReload server.)
- Enter the command
docker ps -a
. The result should look something like this:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f29f9d4ae993 docusaurus-tutorial_docusaurus "docker-entrypoint.s…" 3 minutes ago Up 3 minutes 0.0.0.0:3000->3000/tcp, 0.0.0.0:35729->35729/tcp docusaurus-tutorial_docusaurus_1
- Note that you now have a Docker container based on the docusaurus-tutorial_docusaurus Docker image. This is running the Tutorial app.
Cleaning Up
- In the Docker container, press "Ctrl-C" to stop the Docusaurus server.
- Remove the Docusaurus Tutorial app by entering the following commands:
cd
cd docker-docu
sudo rm -r docusaurus-tutorial
- Note that you had to delete your tutorial app with the "sudo" command because it was owned by root instead of your regular username.
- To delete all Docker networks, enter the command
docker network prune -f
.. - To delete all of the Docker containers, enter the following commands:
for i in $(docker ps -a -q)
do
docker kill $i; wait;
docker rm -f $i; wait;
done;
- To view the list of Docker containers, enter the command
docker ps -a
. This list should now be empty. - To view the list of Docker images, enter the command
docker images -a
. - To delete all of these Docker images, enter the following commands:
for i in $(docker images -a -q)
do
docker kill $i; wait;
docker rmi -f $i; wait;
done;
- To view the list of Docker images, enter the command
docker images -a
. This list should now be empty.