Skip to content

Conversation

@gajeshbhat
Copy link
Contributor

@gajeshbhat gajeshbhat commented Aug 7, 2025

Summary

This PR makes the Docker daemon start automatically after installation by default, with a --no-autostart opt-out flag. This addresses issue #124 and aligns with the current design philosophy of get.docker.com.

Problem

Users need an option to automatically start the Docker daemon after installation, as service management differs between distributions. Currently, users must manually run sudo systemctl start docker and sudo systemctl enable docker after installation.

Solution

The script now automatically starts and enables the Docker daemon by default:

  • Daemon starts automatically after installation
  • Use --no-autostart flag to skip daemon start
  • Automatically detects systemd vs traditional init systems
  • Uses appropriate commands for each distribution:
    • systemdsystemctl start docker && systemctl enable docker
    • Traditional: service docker start && chkconfig docker on (or update-rc.d)
  • Dry-run: Shows exactly what commands will be executed

Usage

# Install Docker (daemon starts automatically)
sudo sh install.sh

# Install Docker without starting daemon
sudo sh install.sh --no-autostart

# See what would happen (dry-run)
sudo sh install.sh --dry-run

@gajeshbhat gajeshbhat force-pushed the feature/daemon-start-option branch from b8ecd36 to b99efe2 Compare August 7, 2025 04:08
@gajeshbhat gajeshbhat mentioned this pull request Aug 7, 2025
@gajeshbhat
Copy link
Contributor Author

@thaJeztah Can you kindly take a look ? Do you think the feature would be useful?

@thaJeztah
Copy link
Member

Oh! This one dropped off my list; I think we actually had a conversation internally to consider making this the default so that rpm and deb packages installed using the convenience script (get.docker.com) would always result in a running daemon.

The current script tried to align with the general conventions / expectations of rpm packages (which don't start services after installation), but as the get.docker.com script is considered a more "opinionated" way to install the docker packages, and meant for convenience (not production scenarios), we could consider doing this by default.

I had to dig back the discussion related to it, but I think it was when we made this change in the docs, which also was changed to automatically start the daemon;

We could add an option to not start it if we decide to make that change (--disable-start or --install-only or something along those lines)

@vvoland WDYT?

@gajeshbhat gajeshbhat force-pushed the feature/daemon-start-option branch from ac8d41c to 7d92938 Compare October 2, 2025 06:32
@gajeshbhat gajeshbhat requested a review from vvoland October 2, 2025 06:33
@gajeshbhat
Copy link
Contributor Author

Oh! This one dropped off my list; I think we actually had a conversation internally to consider making this the default so that rpm and deb packages installed using the convenience script (get.docker.com) would always result in a running daemon.

The current script tried to align with the general conventions / expectations of rpm packages (which don't start services after installation), but as the get.docker.com script is considered a more "opinionated" way to install the docker packages, and meant for convenience (not production scenarios), we could consider doing this by default.

I had to dig back the discussion related to it, but I think it was when we made this change in the docs, which also was changed to automatically start the daemon;

We could add an option to not start it if we decide to make that change (--disable-start or --install-only or something along those lines)

@vvoland WDYT?

Thanks for adding more context. I don't have a strong opinion on whether this feature should be default/non-default. I would personally like a --autostart option so that the default behaviour is as currently expected, ensuring that people who don't use this option/not aware of the update are not surprised if they have an automation script(s) that pulls the latest version of this script.

@vvoland
Copy link
Contributor

vvoland commented Oct 2, 2025

Yeah something like --no-autostart would also be fine.

@thaJeztah
Copy link
Member

Heh, yeah, for context; the get.docker.com script has had many debates over the years; it's generally "bad practice" to just curl | sudo sh a script; it's risky, and even more so if the script involves trying to detect what commands to run; potentially changing system settings that were already set; it's the reason it prints a warning if it discovers that docker is already installed, because this may mean it's installed through other means, with different configs. So it's much better to install things "manualy" (which could mean a customised variants of the steps, but targeted at the distro you're using)

That said; it's it sure is REALLY convenient to use, so the script is unlikely to go away; we consider it an opinionated way to configure things, which may involve things like this (automatically start), and with the proper warnings in place ("know what you're opting into when using the script") both in the script, the "dry run" option to check what you're about to run, and warnings in our docs, I think that's perfectly fine to do.

@gajeshbhat
Copy link
Contributor Author

Heh, yeah, for context; the get.docker.com script has had many debates over the years; it's generally "bad practice" to just curl | sudo sh a script; it's risky, and even more so if the script involves trying to detect what commands to run; potentially changing system settings that were already set; it's the reason it prints a warning if it discovers that docker is already installed, because this may mean it's installed through other means, with different configs. So it's much better to install things "manualy" (which could mean a customised variants of the steps, but targeted at the distro you're using)

That said; it's it sure is REALLY convenient to use, so the script is unlikely to go away; we consider it an opinionated way to configure things, which may involve things like this (automatically start), and with the proper warnings in place ("know what you're opting into when using the script") both in the script, the "dry run" option to check what you're about to run, and warnings in our docs, I think that's perfectly fine to do.

I have refactored it to make autostart the default behaviour with a --no-autostart opt-out flag. CC: @vvoland

@gajeshbhat gajeshbhat changed the title Add --start-daemon option to automatically start Docker service Automatically start Docker service Oct 4, 2025
@gajeshbhat gajeshbhat changed the title Automatically start Docker service Automatically start Docker service with --no-autostart disable label Oct 4, 2025
@gajeshbhat gajeshbhat changed the title Automatically start Docker service with --no-autostart disable label Automatically start Docker service with --no-autostart disable option Oct 4, 2025
Copy link
Contributor

@vvoland vvoland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good to me. One last thing though - please change the new echos to output to stderr ❤️

@gajeshbhat
Copy link
Contributor Author

gajeshbhat commented Oct 9, 2025

Thanks, looks good to me. One last thing, though - please change the new echos to output to stderr ❤️

Thank you for the review @vvoland. I have updated the suggested changes and pushed the commit. Please let me know if you have any questions. Cheers.

@vvoland
Copy link
Contributor

vvoland commented Oct 10, 2025

Oh, could you please rebase the PR on top of the latest master (after #530 was merged)?

The test in the CI pipeline wasn't being ran correctly before, so the script wasn't even ran for this PR 🙈

@gajeshbhat
Copy link
Contributor Author

@vvoland rebased and pushed. Please let me know if you have any questions. Cheers.

@gajeshbhat gajeshbhat requested a review from vvoland October 11, 2025 04:42
@vvoland
Copy link
Contributor

vvoland commented Oct 13, 2025

Looks like it fails in a container environment: https://github.com/docker/docker-install/actions/runs/18424536661/job/52594868483?pr=518

Also, can you please rebase so it doesn't actually include the merge commits? ❤️

@gajeshbhat gajeshbhat force-pushed the feature/daemon-start-option branch 2 times, most recently from 22f4812 to c71834f Compare October 18, 2025 07:45
@gajeshbhat
Copy link
Contributor Author

Looks like it fails in a container environment: https://github.com/docker/docker-install/actions/runs/18424536661/job/52594868483?pr=518

Also, can you please rebase so it doesn't actually include the merge commits? ❤️

@vvoland Did a clean rebase and fixed errors from CI earlier. Can you please approve the PR workflow runs so that I can check to make sure my release and fix went as expected? Thanks again for the feedback. Cheers.

@gajeshbhat
Copy link
Contributor Author

@vvoland Any update on this PR?

@vvoland
Copy link
Contributor

vvoland commented Nov 4, 2025

Sorry, this one went off my radar!

Approved the workflows

@gajeshbhat gajeshbhat force-pushed the feature/daemon-start-option branch from c71834f to 2794aef Compare November 27, 2025 05:53
@gajeshbhat
Copy link
Contributor Author

@vvoland sorry for the delayed reply. I have made some fixes and pushed a commit, Can you kindly approve the workflow so that I can test my changes. I did test them locally but would be good to test it on the Pipeline. Please let me know if you have any questions. Cheers.

@gajeshbhat
Copy link
Contributor Author

@vvoland Can you please approve the workflow ? I made fixes after the last failure.

@docker docker deleted a comment from 742764146 Dec 2, 2025
@vvoland
Copy link
Contributor

vvoland commented Dec 2, 2025

Sorry for missing! Approved

@gajeshbhat gajeshbhat requested a review from vvoland December 2, 2025 23:15
@gajeshbhat gajeshbhat force-pushed the feature/daemon-start-option branch 2 times, most recently from 472bcdb to f76b0da Compare December 6, 2025 03:50
Copy link
Contributor

@vvoland vvoland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. @thaJeztah PTAL

@thaJeztah
Copy link
Member

Left some comments / thoughts; I gave it a quick go to look what it looked like with my suggestions, and opened a PR against your branch; if you merge that PR, the changes should show up in this PR, and we can review / discuss those changes;

@gajeshbhat gajeshbhat force-pushed the feature/daemon-start-option branch from 9aa53d9 to 10b5c89 Compare December 10, 2025 04:55
This PR makes the Docker daemon start automatically after installation
by default, with a --no-autostart opt-out flag. This addresses issue docker#124
and aligns with the "opinionated convenience" philosophy of get.docker.com.

Changes:
- Autostart enabled by default (AUTOSTART=1)
- Added --no-autostart flag to opt-out
- Smart systemd detection using /run/systemd/system directory check
- Falls back to traditional service management (service/chkconfig/update-rc.d)
- Uses sh_c pattern for proper dry-run support
- All informational messages output to stderr

The systemd detection checks for /run/systemd/system directory which only
exists when systemd is actually running as PID 1. This prevents failures
in container environments where systemctl is installed but systemd is not
running.

Tested across all supported distributions:
- Ubuntu (20.04, 22.04, 24.04)
- Debian (11, 12)
- CentOS Stream (8, 9)
- Fedora (40, 41)
- RHEL/AlmaLinux (8, 9)

Fixes docker#124

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Gajesh Bhat <gajeshbht@gmail.com>
@gajeshbhat gajeshbhat force-pushed the feature/daemon-start-option branch from 10b5c89 to 7d4c5e2 Compare December 10, 2025 04:57
@gajeshbhat
Copy link
Contributor Author

Left some comments / thoughts; I gave it a quick go to look what it looked like with my suggestions, and opened a PR against your branch; if you merge that PR, the changes should show up in this PR, and we can review / discuss those changes;

Let's run the CI check and see if this works. Thanks for the detailed review. Cheers.

@gajeshbhat gajeshbhat requested a review from thaJeztah December 10, 2025 05:03
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

but would like another review from @vvoland as I made some of the last changes 😅

@thaJeztah thaJeztah requested a review from vvoland December 10, 2025 16:20
@vvoland vvoland merged commit 8b33a64 into docker:master Dec 11, 2025
9 checks passed
@gajeshbhat
Copy link
Contributor Author

Thank you both @vvoland @thaJeztah . It was fun collaborting on this PR. My understanding of docker has definitly improved after this.Looking forward to contributing more in the future. Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants