Recommended Free Tools
On a newly launched Amazon Linux 2023 EC2 instance, user data can install Docker and start its service automatically on first boot. Add a shell script to the instance’s launch settings, then connect after initialization and verify the installation with docker info. The commands below are specific to the Amazon Linux 2023 path documented by AWS; use the selected AMI’s own installation instructions for other operating systems.
What EC2 user data does
EC2 user data is launch-time input for configuring an instance. Linux instances can use shell scripts or cloud-init directives, and Amazon Linux 2023 processes user data through its customized cloud-init package. By default, user-data scripts and cloud-init directives run during the instance’s initial launch, not every time it reboots. See AWS’s EC2 user data documentation and Amazon Linux 2023’s cloud-init documentation.
As an Amazon Associate I earn from qualifying purchases.
First-boot configuration adds time to startup. Allow a few minutes for the commands to finish before treating the instance as ready. This is a procedural allowance from AWS, not a fixed boot-time guarantee.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Add a Docker installation script
When launching a new Amazon Linux 2023 instance, enter the following in its user-data field as a shell script:
#1 Best Overall
#!/bin/bash
yum update -y
yum install docker -y
service docker start
usermod -a -G docker ec2-user
The update, installation, service-start, and group-membership operations follow AWS’s Amazon Linux Docker guidance. AWS documents the package command as sudo yum install docker; the -y flag in the script makes that step noninteractive. A boot-time shell script runs with startup privileges, so the commands do not use sudo. Consult AWS’s Docker instructions for Amazon Linux for the documented command context.
- In the EC2 launch workflow, choose an Amazon Linux 2023 AMI.
- Open the advanced details or user-data setting for the instance and paste the script into the user-data field.
- Complete the remaining instance settings and launch the instance.
- Wait for startup tasks to complete, then connect to the instance and verify Docker.
Verify Docker after connecting
Run docker info in a new login session. AWS documents this command as a way to check Docker after installation. If the script added ec2-user to the docker group, a fresh login is needed for that group change to take effect. Until then, you can try the check with sudo docker info.
Rank #2
- Used Book in Good Condition
Adding a user to the Docker group is optional: Docker can be installed and started without it. It is a convenience for running Docker commands without sudo, but group membership grants privileged access. Only add accounts that should have that access.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsTroubleshoot a script that did not complete
Check cloud-init output
Connect to the instance and inspect /var/log/cloud-init-output.log for user-data command output and errors. A package installation or update can extend boot time, so check the log and allow initialization to finish before diagnosing a timeout.
Know what happens when user data changes
Changing user data on a stopped instance makes the updated contents visible after restart, but under the default behavior that change does not make the script run again. Do not rely on editing user data as a rerun mechanism. For repeatable configuration updates, design an explicit cloud-init or system-service process, or create an image or launch-automation workflow that applies the desired setup.
Keep standalone Docker and ECS bootstrap separate
The script above is for a standalone Amazon Linux 2023 Docker host. ECS container-instance bootstrap has a separate service-ordering concern: AWS explains that Docker and ECS systemd units can wait for cloud-init, while cloud-init waits for user data to finish. Synchronously starting Docker or ECS from user data in that setup can therefore deadlock. AWS’s documented ECS-agent workaround is systemctl enable --now --no-block ecs.service; it is specific to the ECS agent context, not a general replacement for the Docker start command in the standalone script. See AWS’s ECS agent installation guidance and ECS container-instance bootstrap instructions.
Rank #4
AWS also cautions that custom Docker daemon configurations are unsupported in ECS because they can conflict with later changes or features. Do not apply standalone-host assumptions to an ECS-managed container instance.
When to use a different setup
User data is a straightforward fit for one-time setup on a newly launched host. For recurring changes or a fleet of instances, a repeatable configuration-management or image-building approach can provide more control than a launch script, though it requires its own operational design. In every case, package commands and service behavior depend on the chosen operating system and AMI; the commands here are not established for Ubuntu, Debian, or Windows.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




