Scope:
Student will:
- Build a Docker image locally using a Dockerfile.
- Use an image from Docker Hub or build a custom image (Nginx, or Python app).
- Assign a network and volume to the container.
- Push the image to Docker Hub.
- Push the Dockerfile and project files to GitHub.
Steps to Complete the Project
Ensure that the student has: • A GitHub account • A Docker Hub account
mkdir docker-git-project cd docker-git-project
Students can use Redis or any other image they choose. Here’s an example for Redis:
#Use Redis as the base image: FROM redis:latest
#Set environment variables: ENV ALLOW_EMPTY_PASSWORD=yes
#Expose the default Redis port: EXPOSE 6379
#Command to run Redis: CMD ["redis-server"]
docker build -t my-redis-image .
#Verify the image: docker images
#Create a Docker Network
docker network create my-Jibola-network
#Create a Docker Volume docker volume create my-Jibola-data
docker run -d \ --name my-redis-container \ --network my-custom-network \ --mount type=bind,source=my-redis-data,target=/data \ -p 6379:6379 \ my-redis-image
#Verify that the container is running: docker ps
- Login to Docker Hub: docker login
- Tag the Image: docker tag my-redis-image /my-redis-image:v1
- Push the Image: docker push /my-redis-image:v1
#Verify on Docker Hub that the image was uploaded.
- Initialize Git git init
- Create a .gitignore file to ignore unnecessary files: echo "node_modules/" >> .gitignore echo ".DS_Store" >> .gitignore echo ".env" >> .gitignore
- Add and Commit Files git add . git commit -m "Initial Docker project commit"
- Create a GitHub Repository • Go to GitHub • Create a new repository (e.g., docker-git-project) • Copy the remote URL
- Push to GitHub git remote add origin git branch -M main git push -u origin main
Check Docker • Run: docker ps docker images docker network ls docker volume ls
Check GitHub • Visit the repository and confirm the Dockerfile and other files are present.
Check Docker Hub • Visit https://hub.docker.com/ and confirm that the pushed image exists.