Skip to content

Commit 4153beb

Browse files
committed
📝 Update Readme.md
1 parent 9881f1e commit 4153beb

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This section highlights the modifications made to the original project as descri
1010

1111
- Creating a Docker-driven Go development workflow
1212
- Add live realod using [air-verse/air](https://github.com/air-verse/air)
13+
- Add Docker image (production)
1314

1415
---
1516
## Setup Mysql docker container
@@ -100,6 +101,65 @@ SELECT user, host FROM mysql.user;
100101
dsn := flag.String("dsn", "web:pass@tcp(mysql:3306)/snippetbox?parseTime=true", "MySQL data source name")
101102
```
102103

104+
## Docker Compose Production
105+
106+
> [!TIP]
107+
> Create self signed tls certificate & create `.env` before run docker compose
108+
> the generate_cert.go file should be located under `/usr/local/go/src/crypto/tls` or `/usr/lib/go/src/crypto/tls` (Manjaro/Arch)
109+
>
110+
> #### Generate Certificate
111+
> ```bash
112+
> mkdir -p tls
113+
> cd tls
114+
> go run /usr/local/go/src/crypto/tls/generate_cert.go --rsa-bits=2048 --host=localhost
115+
> ```
116+
117+
```yml
118+
services:
119+
web:
120+
image: ghcr.io/nmdra/snipbox:latest
121+
container_name: snipbox-prod
122+
ports:
123+
- "4000:4000" # default app port
124+
env_file:
125+
- .env
126+
volumes:
127+
- ./tls/:/tls/ # TLS cert directory
128+
networks:
129+
- snipbox-net
130+
depends_on:
131+
db:
132+
condition: service_healthy
133+
134+
db:
135+
image: mysql:lts
136+
# container_name: snipbox-db
137+
restart: unless-stopped
138+
environment:
139+
MYSQL_ROOT_PASSWORD: root
140+
MYSQL_DATABASE: snippetbox
141+
MYSQL_USER: web
142+
MYSQL_PASSWORD: pass
143+
ports:
144+
- "3306:3306" # Expose MySQL port (Optional)
145+
volumes:
146+
- mysql-data:/var/lib/mysql
147+
networks:
148+
- snipbox-net
149+
healthcheck:
150+
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
151+
interval: 5s
152+
timeout: 5s
153+
retries: 2
154+
155+
volumes:
156+
mysql-data:
157+
external: true
158+
159+
networks:
160+
snipbox-net:
161+
driver: bridge
162+
```
103163

104164
<div align="center">
105165
<a href="blog.nimendra.xyz"> 🌎 nmdra.xyz</a> |

0 commit comments

Comments
 (0)