Installing Docker for Parrot OS

Terminal Commands

Open your terminal and type the following commands :

$sudo apt update

Install docker dependencies

$sudo apt install apt-transport-https ca-certificates curl gnupg lsb-release -y

Get the docker PGP key

$curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

In the command below be sure to replace with whatever version of debian you are running, i.e., buster, bullseye, stretch

$echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian buster stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Perform an update for installed binaries.

$sudo apt update
$sudo apt -y install docker-ce docker-ce-cli containerd.io

Add Username to Docker Group

Sometimes you do not want to use docker with sudo account. You can add another username to docker group so that sudo command is not necessary for the docker user

$sudo usermod -aG docker your_username

That's it. You should be able to run docker commands in your system.

Docker

This part was first created Monday, March 7, 2022. From my Securanalyst.blogspot.com

$docker images
$docker search [image]

Downloading an image

$docker pull [image]

// example install an ubuntu image
$docker pull ubuntu

Alternatively

$docker run [image]
// run the image
$docker run ubuntu

Useful information about containers

To get a list of all running containers

$docker ps

This will exit, because it is not set to run in the background capabilities. To make this run in the background run

$docker run -it -d ubuntu
// where the flag -it stands for interactive terminal
// where the flag -d activates daemon / service mode

To get a list of all exited containers

$docker ps -a

You can also type the first few unique characters of the id

$docker attach [CONTAINER ID]

Image persistance

To make this image persist press the key sequence below while not letting go off Cntrl key:

Ctrl + p 
Ctrl + q

Even when you exit (Ctrl+d), this container will persist.

Run bash

To run a bash or any other pre-inbuilt ubuntu command inside the ubuntu container image

$docker run -it ubuntu /bin/bash

This will open up a bash shell similar to ubuntu, with ubuntu capabilities quite similar to the wsl, which is absolutely awesome.

To exit, Ctrl + d

Accessing Apps

$docker run -it -d -p 8080:80 nginx

This ports are not accessible (by default) outside the container for security purposes. Access the nginx on localhost with the port on the browser to stop the process

$docker stop [container_id]

Run web app

To run web applications on container, that we want to run continuously.

$docker run -it -d --restart unless-stopped -p 8080:80 nginx

To remove a container:

$docker rm [container_id]

Saving changes to image

To save changes to image like ubuntu

$docker run -it ubuntu
$apt udpate
$apt dist-upgrade
$apt install apache2
$/etc/init.d/apache2 status
$/etc/init.d/apache2 start
$apt install vim-nox

Commit changes

Disconnect using: Ctrl + p Ctrl + q

$ docker commit [container_id] [preferred name of image:version number]

// For example
$docker commit [container-id] docker build -t lltv/apache:1.0 .

The period (.) at the end is to create the image in current directory

Automate the process by creating a Dockerfile

First, create and open file called "Dockerfile"

$touch Dockerfile
$nano Dockerfile

Then you can paste the following (Edit where necessary):

FROM ubuntu
MAINTAINER your_username <your_email@example.com>

# Skip prompts
ARG DEBIAN_FRONTEND=noninteractive

# Update packages
RUN apt update; apt dist-upgrade -y

# Install packages
RUN apt install -y apache2 vim-nox

# Set entrypoint
ENTRYPOINT apache2ctl -D FOREGROUND

Then save and exit nano.

The next command must be run from the same location that contains the Dockerfile

$docker build -t lltv/apache:1.1 .

// Important! note the period (.) at the end

to remove an image

$docker images
$docker rmi [image id]

If you encounter any error; refer to the container id and remove it using:

docker rm [container_id]

links

social