2019-12-22 17:23:18 +00:00
---
path: "/docs/installation-guide-docker"
2020-02-17 14:22:26 +00:00
title: "Docker Setup"
2019-12-22 17:23:18 +00:00
---
2020-02-17 14:22:26 +00:00
### Pre-requisites
Before proceeding, make sure you have the latest version of `docker` and `docker-compose` installed.
2019-12-22 17:23:18 +00:00
2020-02-17 14:22:26 +00:00
As of now[at the time of writing this doc], we recommend
2019-12-23 06:26:25 +00:00
2020-02-17 14:22:26 +00:00
```bash
$ docker --version
Docker version 19.03.3, build a872fc2f86
$ docker-compose --version
docker-compose version 1.25.3, build d4d1b42b
```
2020-01-05 17:56:22 +00:00
2020-02-17 14:22:26 +00:00
## Development environment
2020-01-05 17:56:22 +00:00
2020-02-17 14:22:26 +00:00
1. Clone the repository.
2019-12-22 17:23:18 +00:00
2020-02-17 14:22:26 +00:00
```bash
$ git clone https://github.com/chatwoot/chatwoot.git
```
2019-12-22 17:23:18 +00:00
2020-02-17 14:22:26 +00:00
2. Make a copy of the example environment file and modify as required [optional].
2019-12-22 17:23:18 +00:00
2020-02-17 14:22:26 +00:00
```bash
$ cp .env.example .env
```
2019-12-22 17:23:18 +00:00
2020-02-17 14:22:26 +00:00
If you want to set the password for redis when you run docker-compose, set any string value to the environment variable `REDIS_PASSWORD` in the `.env` file.
This will secure the redis running inside docker-compose with the given password.
Also this will be automatically picked up by the app server and sidekiq, to authenticate while making connections to redis server.
2019-12-22 17:23:18 +00:00
2020-02-17 14:22:26 +00:00
3. Build the images.
2019-12-24 21:33:02 +00:00
2020-02-17 14:22:26 +00:00
```bash
$ docker-compose build
```
2019-12-24 21:33:02 +00:00
2020-02-17 14:22:26 +00:00
4. After building the image or after destroying the stack you would have to reset the database using the following command.
2019-12-22 17:23:18 +00:00
2020-02-17 14:22:26 +00:00
```bash
$ docker-compose run --rm rails bundle exec rails db:reset
```
2019-12-22 17:23:18 +00:00
2020-02-17 14:22:26 +00:00
5. To run the app,
2019-12-22 17:23:18 +00:00
2020-02-17 14:22:26 +00:00
```bash
$ docker-compose up
```
2019-12-22 17:23:18 +00:00
2020-02-17 14:22:26 +00:00
* Access the rails app frontend by visiting `http://0.0.0.0:3000/`
* Access Mailhog inbox by visiting `http://0.0.0.0:8025/` (You will receive all emails going out of the application here)
* Access Sidekiq Web UI by visiting `http://0.0.0.0:3000/sidekiq` (You need to login with administrator account to access sidekiq)
#### Login with credentials
```
url: http://localhost:3000
user_name: john@acme.inc
password: 123456
````
6. To stop the app,
```bash
$ docker-compose down
```
2019-12-22 17:23:18 +00:00
### Running rspec tests
2020-02-17 14:22:26 +00:00
For running the complete rspec tests,
```bash
$ docker-compose run --rm rails bundle exec rspec
```
For running specific test,
```bash
$ docker-compose run --rm rails bundle exec rspec spec/< path-to-file > :< line-number >
```
## Production environment
To debug the production build locally, set `SECRET_KEY_BASE` environment variable in your `.env` file and then run the below commands:
```bash
$ docker-compose -f docker-compose.production.yaml build
$ docker-compose -f docker-compose.production.yaml up
```
## Debugging mode
2019-12-22 17:23:18 +00:00
2020-02-17 14:22:26 +00:00
To use debuggers like `byebug` or `binding.pry` , use the following command to bring up the app instead of `docker-compose up` .
2019-12-22 17:23:18 +00:00
2020-02-17 14:22:26 +00:00
```bash
$ docker-compose run --rm --service-port rails
```
2019-12-22 17:23:18 +00:00
2020-02-17 14:22:26 +00:00
## Troubleshooting
If there is an update to any of the following
- `dockerfile`
- `gemfile`
- `package.json`
- schema change
2019-12-22 17:23:18 +00:00
2020-02-17 14:22:26 +00:00
Make sure to rebuild the containers and run `db:reset` .
2019-12-22 17:23:18 +00:00
2020-02-17 14:22:26 +00:00
```bash
$ docker-compose down
$ docker-compose build
$ docker-compose run --rm rails bundle exec rails db:reset
$ docker-compose up
```