Skip to content

Commit 63efbff

Browse files
committed
fix: detect network delete/recreate by Docker ID during sync
Network sync compared only by name, so a network deleted and recreated with the same name but different attributes (driver, attachable, etc.) was reported as already in sync. Store Docker's network Id (dockerId column) and compare it against the live Id during sync. A name match with a dockerId mismatch is now surfaced as a new "changed" state, with an Update action to refresh the DB row from the live network. Fixes Dokploy#5179
1 parent 523e8f4 commit 63efbff

7 files changed

Lines changed: 9310 additions & 8 deletions

File tree

‎apps/dokploy/components/dashboard/networks/sync-networks.tsx‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const SyncNetworks = ({ serverId }: Props) => {
3434
const importMutation = api.network.import.useMutation();
3535
const removeMutation = api.network.remove.useMutation();
3636
const recreateMutation = api.network.recreate.useMutation();
37+
const resyncMutation = api.network.resync.useMutation();
3738

3839
const toggleSelected = (name: string) => {
3940
setSelected((prev) => {
@@ -102,6 +103,20 @@ export const SyncNetworks = ({ serverId }: Props) => {
102103
}
103104
};
104105

106+
const onResync = async (networkId: string, name: string) => {
107+
try {
108+
await resyncMutation.mutateAsync({ networkId });
109+
toast.success(`Network "${name}" updated from Docker`);
110+
await utils.network.all.invalidate();
111+
await utils.network.networksToSync.invalidate();
112+
await refetch();
113+
} catch (error) {
114+
toast.error("Error updating network", {
115+
description: error instanceof Error ? error.message : "Unknown error",
116+
});
117+
}
118+
};
119+
105120
return (
106121
<Dialog
107122
open={open}
@@ -177,6 +192,43 @@ export const SyncNetworks = ({ serverId }: Props) => {
177192
)}
178193
</div>
179194

195+
{!!data?.changed.length && (
196+
<>
197+
<Separator />
198+
<div className="flex flex-col gap-2">
199+
<span className="text-sm font-medium">
200+
Changed ({data.changed.length})
201+
</span>
202+
<span className="text-xs text-muted-foreground">
203+
These networks were deleted and recreated in Docker under
204+
the same name — attributes in Dokploy are outdated.
205+
</span>
206+
{data.changed.map((changed) => (
207+
<div
208+
key={changed.networkId}
209+
className="flex items-center justify-between gap-3 rounded-lg border border-dashed p-3"
210+
>
211+
<div className="flex items-center gap-3">
212+
<span className="text-sm">{changed.name}</span>
213+
{changed.driver && (
214+
<Badge variant="outline">{changed.driver}</Badge>
215+
)}
216+
</div>
217+
<Button
218+
variant="outline"
219+
size="xs"
220+
isLoading={resyncMutation.isPending}
221+
onClick={() => onResync(changed.networkId, changed.name)}
222+
>
223+
<RotateCcw className="size-3.5" />
224+
Update
225+
</Button>
226+
</div>
227+
))}
228+
</div>
229+
</>
230+
)}
231+
180232
{!!data?.missing.length && (
181233
<>
182234
<Separator />
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE "network" ADD COLUMN "dockerId" text;

0 commit comments

Comments
 (0)