Welcome to the Docker Workshop repository! This project is designed to help students understand and implement containerization using Docker. The repository includes all the resources, examples, and exercises you need to get started with Docker.
- Introduction
- Prerequisites
- Getting Started
- Workshop Outline
- Dockerfile Explained
- Usage
- Pushing to Docker Hub
- Exercises
- Contributing
- License
Docker is a platform for developers and sysadmins to develop, deploy, and run applications with containers. Containers allow you to package an application with all its dependencies into a standardized unit for software development.
This workshop provides hands-on exercises and examples to help you learn the fundamentals of Docker, including building, running, and managing containers.
Before you begin, ensure you have the following installed on your system:
- Docker: Install Docker by following the instructions on the official Docker website.
- Git: Ensure you have Git installed to clone this repository. Get Git from here.
- Docker Hub Account: Create a free Docker Hub account at hub.docker.com if you don’t already have one.
-
Clone this repository:
git clone https://github.com/kadimasum/docker_workshop.git cd docker_workshop -
Navigate to the project folder:
cd docker_workshop -
Run the first example:
Follow the instructions provided in the workshop files.
- What is Docker?
- Benefits of containerization.
- Docker architecture.
- Installing Docker.
- Running your first container.
- Creating a Dockerfile.
- Building images.
- Running containers from images.
- Managing containers with Docker commands.
- Introduction to Docker Compose.
- Creating
docker-compose.ymlfiles. - Running multi-container applications.
- Building and deploying a Django application using Docker.
The Dockerfile is a text file that contains a set of instructions to build a Docker image. Here's how the Dockerfile in this repository was created and how it works:
# Step 1: Use an official Python base image
FROM python:3.9-slim
# Step 2: Set the working directory inside the container
WORKDIR /app
# Step 3: Copy the requirements file to the container
COPY requirements.txt .
# Step 4: Install dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Step 5: Copy the rest of the application code
COPY . .
# Step 6: Expose the application port
EXPOSE 8000
# Step 7: Define the command to run the Django application
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]-
Base Image (
FROM):- The
FROMinstruction specifies the base image for the container. In this case, it uses the official Python 3.9 slim image to keep the container lightweight.
- The
-
Set Working Directory (
WORKDIR):- The
WORKDIRinstruction sets the working directory inside the container where all subsequent commands will be executed. Here,/appis used.
- The
-
Copy Requirements File (
COPY):- The
COPY requirements.txt .command copies therequirements.txtfile (containing Python dependencies) into the working directory.
- The
-
Install Dependencies (
RUN):- The
RUN pip installcommand installs all the dependencies listed in therequirements.txtfile.
- The
-
Copy Application Code (
COPY):- The second
COPY . .command copies the rest of the application code into the container.
- The second
-
Expose Port (
EXPOSE):- The
EXPOSEinstruction specifies the port that the Django application will run on. Here, it’s port8000.
- The
-
Run the Application (
CMD):- The
CMDinstruction defines the command to start the Django application when the container runs. It runs the development server withpython manage.py runserver 0.0.0.0:8000.
- The
docker build -t django-app .docker run -d -p 8000:8000 django-appdocker stop <container_id>docker rm <container_id>Follow these steps to push your Docker image to Docker Hub:
-
Log In to Docker Hub: Log in to Docker Hub using the
docker logincommand. Provide your Docker Hub username and password when prompted.docker login
-
Tag the Docker Image: Tag your Docker image with the format
username/repository:tag. Replaceusernamewith your Docker Hub username,repositorywith the name of the repository you want to create on Docker Hub, andtagwith a version or descriptive label (e.g.,latest).docker tag django-app your_dockerhub_username/django-app:latest
-
Push the Image to Docker Hub: Use the
docker pushcommand to upload your tagged image to Docker Hub.docker push your_dockerhub_username/django-app:latest
-
Verify the Image on Docker Hub: Visit your Docker Hub account, navigate to the repository, and confirm that your image is listed.
Each section in the workshop includes exercises to help reinforce the concepts covered. Complete them step-by-step, and feel free to ask questions if you get stuck.
Example Exercise:
- Create a
Dockerfilefor a simple Django application. - Build an image and run the application in a container.
- Push the image to Docker Hub.
Contributions are welcome! Feel free to fork this repository, submit issues, or create pull requests.
To contribute:
- Fork this repository.
- Create a new branch:
git checkout -b feature/my-feature. - Make your changes and commit them:
git commit -m 'Add some feature'. - Push to the branch:
git push origin feature/my-feature. - Open a pull request.
This repository is licensed under the MIT License. See the LICENSE file for details.