This guide will walk you through setting up Docker and Python on Ubuntu 24.04 LTS, the latest Long Term Support release, ensuring a robust and future-proof development environment.
In this article, you'll learn how to:
- Install Docker on Ubuntu 24.04 LTS: Get Docker up and running to containerize your applications for consistent and portable workflows.
- Validate Docker Installation: Verify your Docker setup with a simple "Hello World" container.
- Set Up Python on Ubuntu 24.04 LTS: Ensure Python, along with essential tools like
pip
andvenv
, is properly configured for your development projects. - Validate Python Setup: Confirm Python and its package manager are ready to go with a quick test.
With clear, step-by-step instructions and hands-on validation, you'll have a fully functional development environment ready to kickstart your projects!
Setting Up Docker on Ubuntu 24.04 LTS
Docker is a game-changer for modern application development, allowing you to build, ship, and run applications in isolated containers. Let's dive into setting up Docker on Ubuntu 24.04 LTS.
Why Docker?
Docker simplifies the entire application lifecycle. It enables you to:
- Simplify Deployment: Create portable, containerized environments that ensure your application runs consistently across different systems.
- Efficiently Manage Databases: Easily provision and manage databases within containers, keeping your development environment clean and organized.
- Isolate Dependencies: Avoid conflicts between project dependencies by encapsulating each project in its own container.
- Enhance Testing: Create consistent and reproducible testing environments, ensuring reliable application behavior.
Step-by-Step Docker Installation on Ubuntu 24.04 LTS
Here’s how to install Docker on Ubuntu 24.04 LTS:
-
Update Your Package Index:
First, update your system's package index to ensure you have the latest package information:
Bashsudo apt update
-
Install Prerequisites:
Install packages that allow
apt
to use repositories over HTTPS:Bashsudo apt install apt-transport-https ca-certificates curl software-properties-common -y
-
Add Docker’s Official GPG Key:
Add Docker’s GPG key to authenticate packages from the Docker repository:
Bashcurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
-
Set Up the Docker Repository:
Add the Docker APT repository to your system's sources list:
Bashecho "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu mantic stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Note: While Ubuntu 24.04 LTS is 'noble', using 'mantic' ensures compatibility as Docker often lags slightly in official support for the newest Ubuntu releases. This is a common practice and generally safe.
-
Update Package Index Again:
Update the package index to include the new Docker repository:
Bashsudo apt update
-
Install Docker Engine:
Finally, install Docker Engine, containerd, and Docker Compose:
Bashsudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
-
Verify Docker Installation:
Check if Docker is installed and running correctly:
Bashsudo systemctl status docker
You should see output indicating that the Docker service is active and running.
Validating Docker
To ensure Docker is working as expected, run the classic "Hello World" container image:
docker run hello-world
If Docker is set up correctly, you'll see a confirmation message from the hello-world
image.
Grant User Docker Access (Optional, Recommended)
By default, Docker commands require sudo
. To run Docker commands without sudo
, add your user to the docker
group:
sudo usermod -aG docker ${USER}
Important: After running this command, restart your current session (log out and log back in) for the changes to take effect.
Setting Up and Validating Python on Ubuntu 24.04 LTS
Python is a highly versatile and widely used programming language, essential for various development tasks, data analysis, and scripting. Ubuntu 24.04 LTS comes with Python 3 pre-installed, but let's validate the installation and set up essential Python
Steps to Validate Python
-
Check Python 3 Installation:
Open your terminal and check if Python 3 is installed by running:
Bashpython3 --version
You should see the Python 3 version
2 printed in the output. -
Test Python Interpreter:
Launch the Python 3 interpreter and run a simple command:
Bashpython3
Once the Python interpreter starts (you'll see
>>>
), type:Pythonprint("Hello, World from Python!")
and press Enter. It should print "Hello, World from Python!". Then, exit the interpreter by typing:
Pythonexit()
-
Install
pip
(Python Package Installer):pip
is the package installer for Python. While it might be pre-installed, ensure it's available and up-to-date:Bashsudo apt update sudo apt install python3-pip -y
-
Validate
pip
:Check the
pip
version:Bashpip3 --version
You should see the
pip
version associated with Python 3. -
Set Up Virtual Environments (
venv
):Virtual environments are crucial for isolating project dependencies. Install the
venv
module:Bashsudo apt install python3-venv -y
-
Create and Test a Virtual Environment:
Create a virtual environment to validate the setup:
Bashpython3 -m venv test_env
This command creates a virtual environment directory named
test_env
. List the directory contents to confirm:Bashls -ltr test_env
To clean up, remove the test environment:
Bashrm -rf test_env
Tips for a Smooth Setup
- Run Commands Sequentially: Execute each command in the provided order and ensure each step completes successfully before proceeding to the next. Pay attention to any error messages and troubleshoot accordingly.
- Restart Session After Docker Group Modification: Remember to restart your session after adding your user to the
docker
group to apply the permissions changes. - Keep Software Updated: Regularly update Docker and Python packages using
sudo apt update
andsudo apt upgrade
to benefit from the latest features, security patches, and bug fixes. - Practice Containerization: Experiment with creating simple Docker images and containers. Start with basic images like
hello-world
and gradually explore more complex applications to solidify your understanding of Docker concepts.
Conclusion
Congratulations! You've successfully set up Docker and validated Python on your Ubuntu 24.04 LTS system. You now have a powerful and versatile development environment ready for your next coding adventure. Embrace containerization with Docker and leverage the flexibility of Python to build amazing applications.
0 comments:
Post a Comment