2020-09-04 05:12:08 +00:00
## Freqtrade with docker without docker-compose
2019-05-25 14:13:18 +00:00
2020-09-04 05:12:08 +00:00
!!! Warning
2021-01-21 11:27:22 +00:00
The below documentation is provided for completeness and assumes that you are familiar with running docker containers. If you're just starting out with Docker, we recommend to follow the [Quickstart ](docker_quickstart.md ) instructions.
2019-05-25 14:13:18 +00:00
2020-09-04 05:12:08 +00:00
### Download the official Freqtrade docker image
2019-05-25 14:13:18 +00:00
2020-09-04 05:12:08 +00:00
Pull the image from docker hub.
2019-05-25 14:13:18 +00:00
2020-09-04 05:12:08 +00:00
Branches / tags available can be checked out on [Dockerhub tags page ](https://hub.docker.com/r/freqtradeorg/freqtrade/tags/ ).
2020-02-08 12:38:45 +00:00
2020-09-04 05:12:08 +00:00
```bash
2020-09-20 09:45:08 +00:00
docker pull freqtradeorg/freqtrade:stable
2020-09-04 05:12:08 +00:00
# Optionally tag the repository so the run-commands remain shorter
2020-09-20 09:45:08 +00:00
docker tag freqtradeorg/freqtrade:stable freqtrade
2020-09-04 05:12:08 +00:00
```
2019-05-25 14:13:18 +00:00
2020-09-04 05:12:08 +00:00
To update the image, simply run the above commands again and restart your running container.
2020-02-08 12:38:45 +00:00
2020-09-04 05:12:08 +00:00
Should you require additional libraries, please [build the image yourself ](#build-your-own-docker-image ).
2020-02-08 12:38:45 +00:00
2020-09-04 05:12:08 +00:00
!!! Note "Docker image update frequency"
2020-09-20 09:45:08 +00:00
The official docker images with tags `stable` , `develop` and `latest` are automatically rebuild once a week to keep the base image up-to-date.
2020-09-04 05:12:08 +00:00
In addition to that, every merge to `develop` will trigger a rebuild for `develop` and `latest` .
2020-05-14 12:40:40 +00:00
2020-09-04 05:12:08 +00:00
### Prepare the configuration files
2020-02-08 12:38:45 +00:00
2020-09-04 05:12:08 +00:00
Even though you will use docker, you'll still need some files from the github repository.
2020-02-08 12:38:45 +00:00
2020-09-04 05:12:08 +00:00
#### Clone the git repository
Linux/Mac/Windows with WSL
```bash
git clone https://github.com/freqtrade/freqtrade.git
```
Windows with docker
```bash
git clone --config core.autocrlf=input https://github.com/freqtrade/freqtrade.git
```
#### Copy `config.json.example` to `config.json`
```bash
cd freqtrade
cp -n config.json.example config.json
```
2020-02-08 12:38:45 +00:00
2020-09-04 05:12:08 +00:00
> To understand the configuration options, please refer to the [Bot Configuration](configuration.md) page.
2020-02-08 12:38:45 +00:00
2020-09-04 05:12:08 +00:00
#### Create your database file
2020-02-08 12:38:45 +00:00
2020-09-04 05:12:08 +00:00
=== "Dry-Run"
``` bash
touch tradesv3.dryrun.sqlite
2020-09-03 02:37:45 +00:00
```
2020-02-08 12:38:45 +00:00
2020-09-04 05:12:08 +00:00
=== "Production"
2020-09-03 02:37:45 +00:00
``` bash
2020-09-04 05:12:08 +00:00
touch tradesv3.sqlite
```
2020-02-10 10:01:33 +00:00
2020-09-03 02:37:45 +00:00
2020-09-04 05:12:08 +00:00
!!! Warning "Database File Path"
Make sure to use the path to the correct database file when starting the bot in Docker.
2020-09-03 02:37:45 +00:00
2020-09-04 05:12:08 +00:00
### Build your own Docker image
Best start by pulling the official docker image from dockerhub as explained [here ](#download-the-official-docker-image ) to speed up building.
2020-09-20 14:26:48 +00:00
To add additional libraries to your docker image, best check out [Dockerfile.technical ](https://github.com/freqtrade/freqtrade/blob/develop/docker/Dockerfile.technical ) which adds the [technical ](https://github.com/freqtrade/technical ) module to the image.
2020-09-04 05:12:08 +00:00
```bash
2020-09-20 14:26:48 +00:00
docker build -t freqtrade -f docker/Dockerfile.technical .
2020-09-04 05:12:08 +00:00
```
2020-09-20 14:26:48 +00:00
If you are developing using Docker, use `docker/Dockerfile.develop` to build a dev Docker image, which will also set up develop dependencies:
2020-09-04 05:12:08 +00:00
```bash
2020-09-20 14:26:48 +00:00
docker build -f docker/Dockerfile.develop -t freqtrade-dev .
2020-09-04 05:12:08 +00:00
```
2020-09-03 02:37:45 +00:00
2020-09-04 05:12:08 +00:00
!!! Warning "Include your config file manually"
For security reasons, your configuration file will not be included in the image, you will need to bind mount it. It is also advised to bind mount an SQLite database file (see [5. Run a restartable docker image ](#run-a-restartable-docker-image )") to keep it between updates.
2020-09-03 19:18:15 +00:00
2020-09-04 05:12:08 +00:00
#### Verify the Docker image
2020-09-03 02:37:45 +00:00
2020-09-04 05:12:08 +00:00
After the build process you can verify that the image was created with:
2020-02-08 12:38:45 +00:00
2020-09-04 05:12:08 +00:00
```bash
docker images
```
2020-09-03 19:22:22 +00:00
2020-09-04 05:12:08 +00:00
The output should contain the freqtrade image.
2020-09-03 02:37:45 +00:00
2020-09-04 05:12:08 +00:00
### Run the Docker image
2020-02-08 12:38:45 +00:00
2020-09-04 05:12:08 +00:00
You can run a one-off container that is immediately deleted upon exiting with the following command (`config.json` must be in the current working directory):
2020-02-10 10:01:33 +00:00
2020-09-04 05:12:08 +00:00
```bash
docker run --rm -v `pwd` /config.json:/freqtrade/config.json -it freqtrade
```
2020-02-08 12:38:45 +00:00
2020-09-04 05:12:08 +00:00
!!! Warning
In this example, the database will be created inside the docker instance and will be lost when you refresh your image.
2020-02-08 12:38:45 +00:00
2020-09-04 05:12:08 +00:00
#### Adjust timezone
By default, the container will use UTC timezone.
If you would like to change the timezone use the following commands:
=== "Linux"
2020-09-03 02:37:45 +00:00
``` bash
2020-09-04 05:12:08 +00:00
-v /etc/timezone:/etc/timezone:ro
# Complete command:
docker run --rm -v /etc/timezone:/etc/timezone:ro -v `pwd` /config.json:/freqtrade/config.json -it freqtrade
2020-09-03 02:37:45 +00:00
```
2020-02-08 12:38:45 +00:00
2020-09-04 05:12:08 +00:00
=== "MacOS"
```bash
docker run --rm -e TZ=`ls -la /etc/localtime | cut -d/ -f8-9` -v `pwd` /config.json:/freqtrade/config.json -it freqtrade
```
!!! Note "MacOS Issues"
The OSX Docker versions after 17.09.1 have a known issue whereby `/etc/localtime` cannot be shared causing Docker to not start.< br >
A work-around for this is to start with the MacOS command above
More information on this docker issue and work-around can be read [here ](https://github.com/docker/for-mac/issues/2396 ).
2020-02-08 12:38:45 +00:00
2020-09-04 05:12:08 +00:00
### Run a restartable docker image
2020-02-08 12:38:45 +00:00
2020-09-04 05:12:08 +00:00
To run a restartable instance in the background (feel free to place your configuration and database files wherever it feels comfortable on your filesystem).
2020-02-08 12:38:45 +00:00
2020-09-04 05:12:08 +00:00
#### 1. Move your config file and database
2020-02-08 12:38:45 +00:00
2020-09-04 05:12:08 +00:00
The following will assume that you place your configuration / database files to `~/.freqtrade` , which is a hidden directory in your home directory. Feel free to use a different directory and replace the directory in the upcomming commands.
2020-02-08 12:38:45 +00:00
2020-09-04 05:12:08 +00:00
```bash
mkdir ~/.freqtrade
mv config.json ~/.freqtrade
mv tradesv3.sqlite ~/.freqtrade
```
2020-02-08 12:38:45 +00:00
2020-09-04 05:12:08 +00:00
#### 2. Run the docker image
2020-09-03 19:19:05 +00:00
2020-09-04 05:12:08 +00:00
```bash
docker run -d \
--name freqtrade \
-v ~/.freqtrade/config.json:/freqtrade/config.json \
-v ~/.freqtrade/user_data/:/freqtrade/user_data \
-v ~/.freqtrade/tradesv3.sqlite:/freqtrade/tradesv3.sqlite \
freqtrade trade --db-url sqlite:///tradesv3.sqlite --strategy MyAwesomeStrategy
2020-09-03 19:19:05 +00:00
```
2020-02-08 12:38:45 +00:00
2020-09-04 05:12:08 +00:00
!!! Note
When using docker, it's best to specify `--db-url` explicitly to ensure that the database URL and the mounted database file match.
!!! Note
All available bot command line parameters can be added to the end of the `docker run` command.
!!! Note
You can define a [restart policy ](https://docs.docker.com/config/containers/start-containers-automatically/ ) in docker. It can be useful in some cases to use the `--restart unless-stopped` flag (crash of freqtrade or reboot of your system).
### Monitor your Docker instance
2020-02-08 12:38:45 +00:00
2020-09-04 05:12:08 +00:00
You can use the following commands to monitor and manage your container:
2020-02-08 12:38:45 +00:00
2020-09-04 05:12:08 +00:00
```bash
docker logs freqtrade
docker logs -f freqtrade
docker restart freqtrade
docker stop freqtrade
docker start freqtrade
```
For more information on how to operate Docker, please refer to the [official Docker documentation ](https://docs.docker.com/ ).
!!! Note
You do not need to rebuild the image for configuration changes, it will suffice to edit `config.json` and restart the container.
### Backtest with docker
The following assumes that the download/setup of the docker image have been completed successfully.
Also, backtest-data should be available at `~/.freqtrade/user_data/` .
```bash
docker run -d \
--name freqtrade \
-v /etc/localtime:/etc/localtime:ro \
-v ~/.freqtrade/config.json:/freqtrade/config.json \
-v ~/.freqtrade/tradesv3.sqlite:/freqtrade/tradesv3.sqlite \
-v ~/.freqtrade/user_data/:/freqtrade/user_data/ \
freqtrade backtesting --strategy AwsomelyProfitableStrategy
```
Head over to the [Backtesting Documentation ](backtesting.md ) for more details.
!!! Note
Additional bot command line parameters can be appended after the image name (`freqtrade` in the above example).