Docker Guide
Prerequisites
-
Install Docker: Ensure Docker is installed and running on your system.
- Visit Docker Install Documentation for detailed instructions.
For Ubuntu:
# Uninstall old versions: for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done # Add Docker's official GPG key: sudo apt-get update sudo apt-get install ca-certificates curl sudo install -m 0755 -d /etc/apt/keyrings sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc sudo chmod a+r /etc/apt/keyrings/docker.asc # Add the repository to Apt sources: echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt-get update # Install docker engine, CLI, containerd, buildx, and compose: sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
To verify the installation, run:
Post-installation steps: https://docs.docker.com/engine/install/linux-postinstall
# Enable docker service and containerd service to start on boot: sudo systemctl enable docker.service sudo systemctl enable containerd.service # Add docker group: sudo groupadd docker # Add your user to the docker group: sudo usermod -aG docker ${USER} # Activate the changes to current user session: newgrp docker # Or restart your system to apply the changes: sudo shutdown -r now # Verify that you can run docker commands without sudo: docker run hello-world # Check docker info and version: docker version docker info
-
A Docker Hub Account:
- Sign up at https://hub.docker.com, if you don't already have an account.
-
Log in to Docker Hub:
- Run the following command to log in to Docker Hub and enter your Docker Hub credentials:
Build and Publish Docker Images
1. Build the Docker Image
- Navigate to the directory containing your
Dockerfile
:
Example:
- Build the Docker image:
- Replace
<image_name>
with the desired name of your image (e.g.,challenge_name
). - Replace
<tag>
with a version or description for the image (e.g.,v1.0
,latest
).
Example:
2. Tag the Docker Image
- Tag your image for Docker Hub by adding your Docker Hub username:
- Replace
<dockerhub_username>
with your Docker Hub username. - Replace
<repository_name>
with the repository name you want to push to.
Example:
3. Push the Docker Image to Docker Hub
- Push the tagged image to Docker Hub:
Example:
4. Retrieve the SHA256 Digest
- After pushing the image, retrieve the digest by running:
Example:
5. Verify the Image on Docker Hub
- Log in to Docker Hub and navigate to your repository to ensure the image has been successfully uploaded.
Notes
- Ensure your
<repository_name>
already exists on Docker Hub or create it before pushing the image. - Use descriptive tags to manage different versions of your Docker images effectively.