Setting up a local development environment is crucial for developers to efficiently build, test, and debug their applications. Docker provides a convenient and consistent way to create isolated environments for development across different operating systems. In this article, we'll guide you through setting up a local development environment using Docker on both Mac and Windows platforms.
Prerequisites
Before getting started, make sure you have the following prerequisites installed on your system:
- Docker Desktop: Download and install Docker Desktop for your respective operating system from the official Docker website.
Setting Up on Mac
Step 1: Install Docker Desktop
- Download Docker Desktop for Mac from the official Docker website.
- Double-click the downloaded
.dmg
file to open the installer. - Drag the Docker icon to the Applications folder to install Docker Desktop.
- Open Docker Desktop from the Applications folder.
Step 2: Pull Ubuntu 20.04 Image
Open Terminal and run the following command to pull the Ubuntu 20.04 image from Docker Hub:
docker pull ubuntu:20.04
Step 3: Run Ubuntu 20.04 Container
Run the following command to start a Docker container based on the Ubuntu 20.04 image:
docker run -it --name my-ubuntu-container ubuntu:20.04
Step 4: Restarting the Container
To restart the container named "my-ubuntu-container" later, use the following command:
docker start my-ubuntu-container
Setting Up on Windows
Step 1: Install Docker Desktop
- Download Docker Desktop for Windows from the official Docker website.
- Double-click the downloaded installer to start the installation process.
- Follow the on-screen instructions to complete the installation.
Step 2: Enable WSL (Windows Subsystem for Linux)
- Open PowerShell as an administrator.
- Run the following command to enable WSL:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Step 3: Install Ubuntu 20.04 Distribution
- Open Microsoft Store and search for "Linux".
- Select the Ubuntu 20.04 distribution and click the "Get" button to install it.
- Once installed, click the "Launch" button to start Ubuntu 20.04.
Step 4: Pull Ubuntu 20.04 Image
Open PowerShell or Command Prompt and run the following command to pull the Ubuntu 20.04 image from Docker Hub:
docker pull ubuntu:20.04
Step 5: Run Ubuntu 20.04 Container
Run the following command to start a Docker container based on the Ubuntu 20.04 image:
docker run -it --name my-ubuntu-container ubuntu:20.04
Step 6: Restarting the Container
To restart the container named "my-ubuntu-container" later, use the following command:
docker start my-ubuntu-container
Conclusion
Setting up a local development environment using Docker on both Mac and Windows platforms is straightforward and provides a consistent environment for development. By following the steps outlined in this article, you can quickly create and manage Docker containers for your development needs. Whether you're working on a Mac or Windows machine, Docker simplifies the process of setting up and managing development environments. Happy coding!
Top comments (0)