Skip to content

Commit

Permalink
fix(docker): apply configuration on first boot
Browse files Browse the repository at this point in the history
The initialization sequence is:
 (1) VM boot
 (2) Write daemon configuration

When the VM boot, the Docker systemd service is started, so the
new configuration is not picked up until the next VM boot.

To fix this, reload the systemd daemon config (to pick up the
systemd service file written by `addHostGateway`) and then restart
the Docker systemd service, which will use the new systemd unit
file as well as any customizations to `daemon.json`.
  • Loading branch information
milas committed Aug 6, 2024
1 parent a8ffb4c commit ac44bbc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions environment/container/docker/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ func (d dockerRuntime) addHostGateway(conf map[string]any) error {
return nil
}

func (d dockerRuntime) reloadAndRestartSystemdService() error {
if err := d.guest.Run("sudo", "systemctl", "daemon-reload"); err != nil {
return fmt.Errorf("error reloading systemd daemon: %w", err)
}
if err := d.guest.Run("sudo", "systemctl", "restart", "docker"); err != nil {
return fmt.Errorf("error restarting docker: %w", err)
}
return nil
}

const systemdUnitFilename = "/etc/systemd/system/docker.service.d/docker.conf"
const systemdUnitFileContent string = `
[Service]
Expand Down
3 changes: 3 additions & 0 deletions environment/container/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ func (d dockerRuntime) Provision(ctx context.Context) error {
if err := d.addHostGateway(conf.Docker); err != nil {
log.Warnln(err)
}
if err := d.reloadAndRestartSystemdService(); err != nil {
log.Warnln(err)
}
return nil
})

Expand Down

0 comments on commit ac44bbc

Please sign in to comment.