Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.git
dist
logs
docs
.env
.env.*
profiles.json
.znf
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Builds the dbclone CLI. The image carries only the static binary and the docker CLI:
# every dump and restore still runs inside your local mongo/mysql containers.
FROM golang:1.26-alpine AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
ARG VERSION=docker
RUN CGO_ENABLED=0 go build -ldflags "-s -w -X main.version=${VERSION}" -o /dbclone .

FROM alpine:3.21
RUN apk add --no-cache docker-cli
COPY --from=build /dbclone /usr/local/bin/dbclone
WORKDIR /work
ENTRYPOINT ["dbclone"]
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ go install github.com/phuthuycoding/dbclone@latest # any OS with Go
or download a binary from [Releases](https://github.com/phuthuycoding/dbclone/releases)
(linux / macOS / windows, amd64 / arm64).

### Or run everything with Docker Compose

No Go, no binary: the repo's [`compose.yaml`](compose.yaml) starts local MongoDB and MySQL from
the official images, already carrying the root credentials dbclone expects, and builds the CLI
into a small image that talks to them over the Docker socket.

```bash
git clone https://github.com/phuthuycoding/dbclone && cd dbclone
docker compose up -d # mongodb + mysql
docker compose run --rm dbclone -check # ✓ Docker, ✓ mongo, ✓ mysql
docker compose run --rm dbclone # add profiles, pick FROM / TO / databases
docker compose run --rm dbclone -from staging -only mongo:shop -yes
```

Profiles persist in the `dbclone-config` volume; logs land in `./logs`. Override ports or
names with `DBCLONE_MONGO_PORT`, `DBCLONE_MYSQL_PORT`, `DBCLONE_MONGO_CONTAINER`,
`DBCLONE_MYSQL_CONTAINER`, and the local root password with `DBCLONE_LOCAL_PASSWORD`
(default `dbclone`; it only guards the databases on your machine).

## Usage

```bash
Expand Down
57 changes: 57 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Everything dbclone needs, with nothing installed on the host but Docker:
#
# docker compose up -d # local MongoDB + MySQL from the official images
# docker compose run --rm dbclone # the CLI itself, talking to them over the Docker socket
#
# Ports, container names and the local root password can be overridden from the
# environment (DBCLONE_MONGO_PORT, DBCLONE_MYSQL_PORT, DBCLONE_MONGO_CONTAINER,
# DBCLONE_MYSQL_CONTAINER, DBCLONE_LOCAL_PASSWORD). The password only guards databases
# on your own machine; dbclone reads it from the containers and never asks for it.

services:
mongodb:
image: mongo:7
container_name: ${DBCLONE_MONGO_CONTAINER:-mongodb}
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: ${DBCLONE_LOCAL_PASSWORD:-dbclone}
ports:
- "${DBCLONE_MONGO_PORT:-27017}:27017"
volumes:
- mongodb-data:/data/db
restart: unless-stopped

mysql:
image: mysql:8.4
container_name: ${DBCLONE_MYSQL_CONTAINER:-mysql}
environment:
MYSQL_ROOT_PASSWORD: ${DBCLONE_LOCAL_PASSWORD:-dbclone}
ports:
- "${DBCLONE_MYSQL_PORT:-3306}:3306"
volumes:
- mysql-data:/var/lib/mysql
restart: unless-stopped

# Not started by `up`; run it on demand: docker compose run --rm dbclone [flags]
dbclone:
build: .
image: dbclone:local
profiles: [cli]
environment:
DBCLONE_MONGO_CONTAINER: ${DBCLONE_MONGO_CONTAINER:-mongodb}
DBCLONE_MYSQL_CONTAINER: ${DBCLONE_MYSQL_CONTAINER:-mysql}
volumes:
- /var/run/docker.sock:/var/run/docker.sock # dbclone runs `docker exec` into the two containers above
- dbclone-config:/root/.config/dbclone # profiles.json (mode 0600) survives between runs
- ./logs:/work/logs # per-run tool output lands next to this file
working_dir: /work
stdin_open: true
tty: true
depends_on:
- mongodb
- mysql

volumes:
mongodb-data:
mysql-data:
dbclone-config:
5 changes: 3 additions & 2 deletions docs/launch/reddit.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ genuinely answers someone's question.

## r/selfhosted — ONLY in the "New Project Megathread" until 2027-01-02 (rule 6, verified)

Comment, Fri 2026-10-16: 3 lines. Rule 2 wants "production ready and have docs" — point at
the README flag table and `-check`. Wednesday exception (rule 5) allows tool posts with the
Comment, Fri 2026-10-16: 3 lines. Lead with `docker compose up -d && docker compose run --rm dbclone`
(nothing but Docker on the host — the self-hosted angle). Rule 2 wants "production ready and
have docs" — point at the README flag table and `-check`. Wednesday exception (rule 5) allows tool posts with the
right flair; still a 3-month-old project is megathread-only, so wait.

## r/commandline — NOT before 2026-11-02 (rule 5: no projects newer than 30 days, verified)
Expand Down
Loading