File size: 6,196 Bytes
9fb1755
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# Docker Hub Setup Guide

This guide will help you deploy your algorithmic trading system to Docker Hub and use it from the cloud.

## Prerequisites

1. **Docker Hub Account**: Create an account at [hub.docker.com](https://hub.docker.com)
2. **Docker CLI**: Ensure Docker is installed and running
3. **Repository**: Create a repository on Docker Hub (optional, will be created automatically)

## Quick Start

### 1. Set Environment Variables

```bash
# Set your Docker Hub username
export DOCKER_USERNAME=yourusername

# Optionally set your password/token (for automated login)
export DOCKER_PASSWORD=yourpassword
```

### 2. Deploy to Docker Hub

```bash
# Deploy with default settings
./scripts/docker-build.sh deploy

# Or use the dedicated deployment script
./scripts/docker-hub-deploy.sh -u yourusername

# Deploy with custom image name and tag
./scripts/docker-hub-deploy.sh -u yourusername -i my-trading-system -t v1.0.0
```

### 3. Use from Docker Hub

```bash
# Start services using Docker Hub images
./scripts/docker-build.sh hub

# Or manually pull and run
docker pull yourusername/algorithmic-trading:latest
docker run -p 8000:8000 yourusername/algorithmic-trading:latest
```

## Detailed Instructions

### Step 1: Create Docker Hub Account

1. Go to [hub.docker.com](https://hub.docker.com)
2. Click "Sign Up" and create an account
3. Verify your email address
4. Create a repository (optional):
   - Click "Create Repository"
   - Name: `algorithmic-trading`
   - Description: "Algorithmic Trading System with FinRL"
   - Visibility: Public or Private

### Step 2: Generate Access Token (Recommended)

1. Go to Docker Hub โ†’ Account Settings โ†’ Security
2. Click "New Access Token"
3. Name: `algorithmic-trading-deploy`
4. Permissions: Read & Write
5. Copy the token (you won't see it again)

### Step 3: Configure Environment

```bash
# Add to your ~/.bashrc or ~/.zshrc
export DOCKER_USERNAME=yourusername
export DOCKER_PASSWORD=your_access_token
```

### Step 4: Deploy

```bash
# Build and deploy
./scripts/docker-hub-deploy.sh -u yourusername

# The script will:
# 1. Build the Docker image
# 2. Run tests (optional)
# 3. Login to Docker Hub
# 4. Tag the image
# 5. Push to Docker Hub
```

### Step 5: Verify Deployment

1. Check your Docker Hub repository: `https://hub.docker.com/r/yourusername/algorithmic-trading`
2. You should see your image with the latest tag

## Usage Examples

### Local Development with Docker Hub

```bash
# Start development environment
DOCKER_USERNAME=yourusername ./scripts/docker-build.sh hub

# Access services:
# - Jupyter Lab: http://localhost:8888
# - Trading System: http://localhost:8000
```

### Production Deployment

```bash
# Deploy to production
docker run -d \
  --name trading-prod \
  -p 8000:8000 \
  -v $(pwd)/data:/app/data \
  -v $(pwd)/logs:/app/logs \
  -v $(pwd)/config.yaml:/app/config.yaml:ro \
  yourusername/algorithmic-trading:latest
```

### Using Docker Compose

```bash
# Create .env file
echo "DOCKER_USERNAME=yourusername" > .env
echo "TAG=latest" >> .env

# Start services
docker compose -f docker-compose.hub.yml up -d
```

## Advanced Usage

### Multiple Tags

```bash
# Deploy with version tags
./scripts/docker-hub-deploy.sh -u yourusername -t v1.0.0
./scripts/docker-hub-deploy.sh -u yourusername -t v1.1.0
./scripts/docker-hub-deploy.sh -u yourusername -t latest
```

### Custom Image Names

```bash
# Deploy with custom name
./scripts/docker-hub-deploy.sh -u yourusername -i my-trading-bot -t production
```

### Automated Deployment

```bash
# Create a deployment script
cat > deploy.sh << 'EOF'
#!/bin/bash
export DOCKER_USERNAME=yourusername
export DOCKER_PASSWORD=your_token
./scripts/docker-hub-deploy.sh -u $DOCKER_USERNAME -t $(date +%Y%m%d)
EOF

chmod +x deploy.sh
./deploy.sh
```

## Troubleshooting

### Login Issues

```bash
# Manual login
docker login -u yourusername

# Check login status
docker info | grep Username
```

### Push Failures

```bash
# Check if repository exists
curl https://hub.docker.com/v2/repositories/yourusername/algorithmic-trading/

# Create repository manually if needed
# Go to Docker Hub โ†’ Create Repository
```

### Permission Issues

```bash
# Check Docker permissions
docker ps

# If permission denied, add user to docker group
sudo usermod -aG docker $USER
# Log out and back in
```

### Network Issues

```bash
# Check Docker Hub connectivity
curl -I https://hub.docker.com

# Use different DNS if needed
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
```

## Best Practices

### 1. Use Access Tokens
- Never use your password in scripts
- Generate access tokens with limited permissions
- Rotate tokens regularly

### 2. Tag Strategically
- Use semantic versioning: `v1.0.0`, `v1.1.0`
- Keep `latest` tag updated
- Use date tags for testing: `2024-01-15`

### 3. Security
- Don't commit credentials to git
- Use environment variables
- Consider private repositories for sensitive code

### 4. Automation
- Set up CI/CD pipelines
- Automate testing before deployment
- Use GitHub Actions or similar

## CI/CD Integration

### GitHub Actions Example

```yaml
# .github/workflows/docker-hub.yml
name: Deploy to Docker Hub

on:
  push:
    tags: ['v*']

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Login to Docker Hub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
      - name: Build and push
        run: |
          docker build -t ${{ secrets.DOCKER_USERNAME }}/algorithmic-trading:${{ github.ref_name }} .
          docker push ${{ secrets.DOCKER_USERNAME }}/algorithmic-trading:${{ github.ref_name }}
```

## Support

- **Docker Hub Documentation**: [docs.docker.com/docker-hub](https://docs.docker.com/docker-hub/)
- **Repository Issues**: Create an issue in this repository
- **Community**: Join Docker Hub community forums

## Next Steps

1. **Set up automated deployment** with CI/CD
2. **Create multiple environments** (dev, staging, prod)
3. **Monitor usage** with Docker Hub analytics
4. **Share with team** by adding collaborators
5. **Scale deployment** to multiple servers