Install Docker on Ubuntu 2404
To install Docker on Ubuntu 24.04, you can follow these steps:
Step 1: Update Your System
First, ensure your system is up-to-date:
sudo apt-get update
sudo apt-get upgrade
Step 2: Install Required Packages
Install the required packages for Docker:
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
Step 3: Add Docker’s Official GPG Key
Add Docker’s official GPG key to your system:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Step 4: Add Docker Repository
Add the Docker repository to APT sources:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Step 5: Update Package Database
Update the package database with Docker packages from the newly added repository:
sudo apt-get update
Step 6: Install Docker
Finally, install Docker:
sudo apt-get install docker-ce docker-ce-cli containerd.io
Step 7: Verify Docker Installation
Verify that Docker is installed correctly by running the hello-world
image:
sudo docker run hello-world
Optional Step: Manage Docker as a Non-root User
To avoid typing sudo
whenever you run the docker
command, add your username to the Docker group:
sudo usermod -aG docker ${USER}
To apply the new group membership, log out and back in.
Optional Step: Enable Docker to Start on Boot
Enable Docker to start on boot:
sudo systemctl enable docker
After following these steps, Docker should be installed and running on your Ubuntu 24.04 system.
single shell script
#!/bin/sh
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
sudo docker run hello-world
sudo usermod -aG docker ${USER}
sudo systemctl enable docker
發佈時間
2024-11-8