Skip to content

Commit c33d800

Browse files
committed
Fix mount shenanigans
1 parent 4c8dfea commit c33d800

File tree

3 files changed

+9
-31
lines changed

3 files changed

+9
-31
lines changed

docker-compose.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ services:
2929
# DISCOPANEL_DATA_DIR=/app/data
3030
# DISCOPANEL_HOST_DATA_PATH=/home/user/data
3131
# (See environment)
32-
- /home/user/data:/app/data
33-
34-
- ./backups:/app/backups
35-
- ./tmp:/app/tmp
32+
- /opt/discopanel/data:/app/data
33+
- /opt/discopanel/backups:/app/backups
34+
- /tmp/discopanel:/app/tmp
3635

3736
# Configuration file, uncomment if you are using a config file (optional, see config.example.yaml for all available options).
3837
#- ./config.yaml:/app/config.yaml:ro

internal/docker/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ func (c *Client) CreateContainer(ctx context.Context, server *models.Server, ser
440440
hostConfig := &container.HostConfig{
441441
PortBindings: portBindings,
442442
Mounts: []mount.Mount{
443-
{Type: mount.TypeBind, Source: dataPath, Target: "/data"},
443+
{Type: mount.TypeBind, Source: dataPath, Target: "/data", BindOptions: &mount.BindOptions{CreateMountpoint: true}},
444444
},
445445
RestartPolicy: container.RestartPolicy{Name: "unless-stopped"},
446446
Resources: container.Resources{

internal/docker/module.go

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
"os"
8-
"path/filepath"
97

108
shellparse "github.com/arkady-emelyanov/go-shellparse"
119
"github.com/docker/docker/api/types/container"
@@ -225,31 +223,12 @@ func (c *Client) parseVolumeMounts(volumeJSON string, aliasCtx *alias.Context) [
225223
continue
226224
}
227225

228-
// Handle path translation when DiscoPanel runs in a container
229-
if mountType == mount.TypeBind {
230-
if envHostDataPath := os.Getenv("DISCOPANEL_HOST_DATA_PATH"); envHostDataPath != "" {
231-
containerDataDir := os.Getenv("DISCOPANEL_DATA_DIR")
232-
if containerDataDir == "" {
233-
containerDataDir = "/app/data"
234-
}
235-
if relPath, err := filepath.Rel(containerDataDir, source); err == nil {
236-
source = filepath.Join(envHostDataPath, relPath)
237-
}
238-
}
239-
}
240-
241-
// Ensure source directory exists for bind mounts
242-
if mountType == mount.TypeBind {
243-
if err := os.MkdirAll(source, 0755); err != nil {
244-
c.log.Warn("Failed to create volume source directory %s: %v", source, err)
245-
}
246-
}
247-
248226
mounts = append(mounts, mount.Mount{
249-
Type: mountType,
250-
Source: source,
251-
Target: target,
252-
ReadOnly: vol.ReadOnly,
227+
Type: mountType,
228+
Source: source,
229+
Target: target,
230+
ReadOnly: vol.ReadOnly,
231+
BindOptions: &mount.BindOptions{CreateMountpoint: true},
253232
})
254233
}
255234

0 commit comments

Comments
 (0)