What is docker?
Docker is kind of like running virtual machines, but in a more efficient method. Rather than having a virtual machine with their own kernel, services, and operating system, why not just re-use some of the resources of our host computer? So it does that, being very careful to prevent anything running on the container from breaking out.
Docker containers are defined in a “Dockerfile”, and its ubiquity makes it a very easy way of spinning up all sorts of services, inside of a Docker image (which can be copied!). Is 1 million more people watching YouTube tonight? Start up 100 containers or however many is needed to host all of their traffic.
Check if you have it installed already
Run these commands to check if docker is already installed:
sudo docker ps
sudo docker compose ls
Installation (Method 1)
Installation (Longer Method 2);
And to check if it is working:
sudo docker ps
sudo docker compose ls
Make our first service
Make a new directory and go into it, and begin editing docker-compose.yml
.
# I'll be using a "docker-test" directory for this
mkdir docker-test
cd docker-test
nano docker-compose.yml
What do we put in it?
version: "3.8"
services:
whoami:
image: traefik/whoami:latest
container_name: whoami
restart: "no"
ports:
- "8080:80"
Save with Ctrl+O
and exit with Ctrl+X
, and fire up the container:
# try this first
sudo docker compose up -d
# If the above command doesn't work, try this one.
# This was the old command which I learned to use, but apparently we're switching to the one without a "-" dash.
sudo docker-compose up -d
If everything is working correctly, it should pull the image from the Main Docker Repository (hub.docker.com). You can now go to the IP address of the server in your browser (If you are running this on your Kali Linux, you can go to localhost:8888
, otherwise figure out what IP address your server is running on and go to <ip address>:8888
on your browser:
Hostname: 2d4207226e80
IP: 127.0.0.1
IP: 172.19.0.2
RemoteAddr: 10.0.0.2:54146
GET / HTTP/1.1
Host: 10.0.0.254:8888
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.5
Connection: keep-alive
Cookie: adminer_permanent=
Upgrade-Insecure-Requests: 1
Huzzah! It works!
Quick, let’s learn how to turn it off before we forget
# Try this first
sudo docker compose down
# If the above doesn't work, try this:
sudo docker-compose down
After this is done, you can check to make sure that there are no services running in the background using your resources with docker ps
.
What’s going on here?
More of the guide will be written later.
Why is this important?
Docker is kind of used with a lot of stuff on the Cloud and in hosting applications, and it is how