Setting up Habitica Locally on Docker

=== Git Settings for Line Endings ===
This section is only relevant if you are using Docker on a Windows PC.
*nix operating systems (Linux and Mac OS X) handle line endings differently than Windows. *nix systems use the line feed (LF) character \n, while Windows uses a combination of a carriage return and line feed, \r\n (CRLF). Since Habitica developers use a variety of operating systems, to allow for maximum compatibility, Git on Windows must be set up to ensure that only LF line endings are committed to the repo.
right|thumb|300px|Configuring the line ending conversions How you set this up depends on whether you will be doing all your code editing directly in Windows or in the Docker container. The appropriate setting can be chosen when installing Git (see the screenshot but read on before you chose an option) or afterwards using a simple command-line tool.
If you will be doing all your code editing in the Docker container, then when presented with the "Configuring the line ending conversions" window, select "Checkout as-is, commit Unix-style line endings". Alternatively, configure that setting from the command line by runninggit config --global core.autocrlf input
If you will be doing your code editing directly on your Windows host machine (i.e., you are using the Docker container to just run the Habitica server and tests), then select "Checkout Windows-style, commit Unix-style line endings", or configure it by runninggit config --global core.autocrlf true
If you chose one setting now and later decide to change how you do your development work, you can use the appropriate git config --global core.autocrlf ... command to change the setting.
For further information on line endings and whitespace in Git, see the "Formatting and Whitespace" section in the Pro Git book.
If you don't want to set the core.autocrlf setting globally, see Dealing with line endings > Per-repository settings to learn how to set it for individual repositories. This will only be relevant to you if you are already using Git for other projects or will be using it for others in future.
==Install Docker==
#Follow Docker's official instructions for installing docker and docker-compose.
#Verify your installation by clicking the Docker Quickstart Terminal icon on your Desktop (Windows) or Launchpad (Mac OS X).
#In the Docker Quickstart Terminal, cd to Habitica's top-level directory (the one that contains the config.json.example file). Remain in that directory for all future steps on this page, unless advised otherwise.
==Use docker-compose to Build and Start Docker Containers==
On July 15, 2020, the process for running Habitica's MongoDB instance changed. The instructions below might no longer be correct. Please update them if you are aware of any way to improve them.
Run this command:docker-compose -f docker-compose.dev.yml up -dThat command will use Habitica's docker-compose.dev.yml file to build Docker containers to run the various parts of a Habitica install: the server, the website client, and a MongoDB database server. All software needed for those containers will be installed automatically during the build process. If you notice errors, read on to the "Review the Server Output" section below.
After the build is complete, if you wish to see the technical details of the three containers, you can run this command:docker ps
At this point, the version of Habitica running in the containers is the version that exists in your local clone of your fork of the repository. You can use git installed on your computer to create new branches in your local clone (i.e., do not use git in the container to create branches). You can used any text editor or IDE installed on your computer to edit Habitica's code (i.e., you do not have to use an editor in the container). After you have made changes, you'll need to update the Docker containers as described in the "Restarting the Local Web Server on Docker" section in Using Your Local Install to Modify Habitica's Website and API.
If you want to stop the containers, run:docker-compose stop
(NB: When you are ready to run Habitica's automatic test suite as described in Using Your Local Install to Modify Habitica's Website and API, that page will show you how to create another Docker container for running the tests.)
==Check the Versions of Node and NPM==
The information in this section has been written by someone not familiar with Docker. If you can improve this section, or if you can improve Habitica's Docker installation process in general, please do so! [edited on 19/09/23 by @diyoyo to take into account docker commands. First edit ever on the Habitica wiki, don't hesitate to give feedback if I messed up something]
The process above should result in the correct versions of node and npm being installed, which are . However its possible you won't have those versions and if not, you must install them yourself.
To check the versions, run: 
docker compose exec client node --version
docker compose exec client npm --version
docker compose exec server node --version
docker compose exec server npm --version
If the versions aren't correct, follow the instructions in the "Install Node and NPM" section of Setting up Habitica Locally on Linux. 
zh:使用Docker本地搭建Habitica
Category:Contributing
Category:Pages with files missing alt tags