Set Up GitHub and Docker
Learning Objectives
- Master the concepts in this lesson
- Apply knowledge through practice
- Build practical skills
- Prepare for next topics
Assignment Overview
This assignment will guide you through setting up essential tools for modern web development: GitHub for version control and collaboration, and Docker for creating consistent development environments. By the end of this guide, you'll have a GitHub account, your first repository, and Docker installed on your system.
George Polya's 4-Step Problem Solving Method
Step 1: Understand the Problem
We need to accomplish three main tasks:
- Create a personal GitHub account for code hosting and version control
- Create our first Git repository to store our code
- Install Docker to create consistent development environments
These tools are essential for modern web development and will be used throughout the PHP WordPress Development course.
Step 2: Devise a Plan
- Set up a GitHub account
- Visit GitHub's website
- Create a new account
- Verify email address
- Set up profile
- Enable two-factor authentication (recommended)
- Create first GitHub repository
- Create a new repository on GitHub
- Initialize with README
- Clone repository to local machine
- Make simple changes and push them
- Install Docker
- Check system requirements
- Download Docker Desktop
- Install Docker Desktop
- Verify installation
- Run a test container
Step 3: Execute the Plan
Part 1: Setting Up a GitHub Account
Step-by-Step Instructions
-
Visit GitHub's Website
Open your web browser and navigate to https://github.com
GitHub's homepage where you can create a new account
-
Sign Up for a New Account
- Click the "Sign up" button
- Enter your email address
- Create a password
- Choose a username (this will be your GitHub identity, so choose carefully)
- Complete the verification process to prove you're not a robot
- Click "Create account"
-
Verify Your Email Address
- GitHub will send a verification email to the address you provided
- Open the email and click the verification link
- This step is required to fully activate your account
-
Complete Your Profile (Optional but Recommended)
- Add a profile picture (helps others identify you)
- Fill in your name
- Add a bio describing your interests or skills
- Add your location (if you're comfortable sharing)
-
Set Up Two-Factor Authentication (2FA) (Highly Recommended)
- Go to Settings → Security → Two-factor authentication
- Click "Enable two-factor authentication"
- Choose your preferred 2FA method (app or SMS)
- Follow the instructions to complete the setup
- Store your recovery codes in a safe place
Part 2: Creating Your First GitHub Repository
What is a Repository?
A repository (or "repo") is like a project folder that contains all your project files and stores each file's revision history. It can be public (anyone can see it) or private (only you and people you explicitly share it with can see it).
graph TD
A[Repository] --- B[Files]
A --- C[Revision History]
A --- D[Issues/Tickets]
A --- E[Wiki/Documentation]
B --- F[Code]
B --- G[Images]
B --- H[Documents]
B --- I[README.md]
C --- J[Commits]
C --- K[Branches]
C --- L[Tags/Releases]
Step-by-Step Instructions
-
Create a New Repository on GitHub
- Click the "+" icon in the top-right corner of GitHub
- Select "New repository"
- Enter a repository name (e.g., "my-first-repo")
- Add an optional description
- Choose to make it public or private
- Check "Initialize this repository with a README"
- Click "Create repository"
Creating a new repository on GitHub
-
Install Git on Your Local Machine (if not already installed)
Before you can work with GitHub locally, you need to have Git installed:
- For Windows: Download and install from https://git-scm.com/download/win
- For Mac: Install via Homebrew with
brew install gitor download from https://git-scm.com/download/mac - For Linux: Use your package manager, e.g.,
sudo apt-get install git(Ubuntu/Debian) orsudo yum install git(Fedora/RHEL)
-
Clone Your Repository to Your Local Machine
- On your repository page, click the green "Code" button
- Copy the HTTPS URL (e.g.,
https://github.com/yourusername/my-first-repo.git) - Open your terminal or command prompt
- Navigate to where you want to store your project:
cd path/to/your/projects - Clone the repository:
git clone https://github.com/yourusername/my-first-repo.git - This will create a new folder with your repository name
-
Make Changes to Your Repository
- Navigate into your repository folder:
cd my-first-repo - Create a new file:
touch index.html(Mac/Linux) orecho > index.html(Windows) - Open the file in your favorite text editor
- Add some basic HTML:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My First Repository</title> </head> <body> <h1>Hello, GitHub!</h1> <p>This is my first GitHub repository.</p> </body> </html> - Save the file
- Navigate into your repository folder:
-
Commit and Push Your Changes
- Check the status of your repository:
git status - Add the new file to staging:
git add index.html - Commit your changes with a message:
git commit -m "Add index.html" - Push your changes to GitHub:
git push origin main(orgit push origin masterfor older repositories) - Enter your GitHub username and password when prompted (or use a personal access token if 2FA is enabled)
- Check the status of your repository:
-
View Your Changes on GitHub
- Go back to your repository page on GitHub and refresh
- You should now see your new index.html file in the file list
- Click on the file to view its contents
- Click on "Commits" to see your commit history
Part 3: Installing Docker
What is Docker?
Docker is a platform that enables developers to build, share, and run applications in containers. Containers are lightweight, portable environments that include everything needed to run an application: code, runtime, libraries, and system tools.
graph TD
A[Docker] --- B[Containers]
A --- C[Images]
A --- D[Dockerfile]
A --- E[Docker Compose]
B --- F[Isolated Environments]
C --- G[Templates for Containers]
D --- H[Instructions to Build Images]
E --- I[Multi-container Applications]
Why Use Docker for Web Development?
- Consistency: "Works on my machine" problems are eliminated
- Isolation: Projects don't interfere with each other
- Version Control: Easy to switch between different versions of PHP, MySQL, etc.
- Simplified Setup: No need to manually install web servers, databases, etc.
- Mirrors Production: Development environment can match production closely
Step-by-Step Instructions
-
Check System Requirements
Before installing Docker Desktop, ensure your system meets the requirements:
- Windows: Windows 10 64-bit: Pro, Enterprise, or Education (Build 16299 or later) or Windows 11
- Mac: macOS 10.15 or newer, with Intel or Apple Silicon processor
- Linux: Various distributions supported, see Docker's documentation
- At least 4GB of RAM (8GB recommended)
- Virtualization enabled in BIOS/UEFI (for Windows and some Linux)
-
Download Docker Desktop
- Visit https://www.docker.com/products/docker-desktop
- Click the "Download for [your OS]" button
- You may need to create a Docker Hub account (free)
-
Install Docker Desktop
For Windows:
- Double-click the downloaded installer (.exe file)
- Follow the installation wizard
- Ensure "Use WSL 2 instead of Hyper-V" is selected if available
- Click "Install" and wait for the installation to complete
- Click "Close" when finished
For Mac:
- Open the downloaded .dmg file
- Drag the Docker icon to the Applications folder
- Open Docker from your Applications folder
- Authorize the installation if prompted
- Wait for Docker to start
For Linux:
- Follow the distribution-specific instructions from Docker's documentation
- Typically involves adding Docker's repository and installing via package manager
-
Start Docker Desktop
- Launch Docker Desktop from your Start menu (Windows) or Applications folder (Mac)
- Wait for Docker to start (you'll see the Docker icon in the system tray/menu bar)
- The first launch may take a few minutes
Docker Desktop running successfully
-
Verify Docker Installation
- Open your terminal or command prompt
- Run the command:
docker --version - You should see output like:
Docker version 20.10.14, build a224086(version numbers may vary) - Run the command:
docker-compose --version - You should see output like:
Docker Compose version v2.3.3(version numbers may vary)
-
Test Docker with a Simple Container
- In your terminal or command prompt, run:
docker run hello-world - Docker will download the hello-world image and run it
- You should see a message indicating that your Docker installation is working correctly
- The output will explain what Docker did to run the container
Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. - In your terminal or command prompt, run: