Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk3 min

How to Install Docker on an Amazon Linux 2023 EC2 Instance with User Data

Automate Docker setup on a new Amazon Linux 2023 EC2 instance with user data, then verify the daemon and understand first-boot and ECS caveats.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Add a Docker installation script

When launching a new Amazon Linux 2023 instance, enter the following in its user-data field as a shell script:

#!/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.

  1. In the EC2 launch workflow, choose an Amazon Linux 2023 AMI.
  2. Open the advanced details or user-data setting for the instance and paste the script into the user-data field.
  3. Complete the remaining instance settings and launch the instance.
  4. 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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Troubleshoot 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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.