Tool that creates lightweight environments called containers for app deployment. Docker is great at creating isolated spaces for your applications to run on while also providing them with OS level dependencies. Great for:
Concepts
Installation
Arch
sudo pacman -S docker
sudo systemctl enable docker.service & sudo systemctl start docker.service
sudo systemctl start docker.socket
Debian
apt update
apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Using Docker
Build Container
docker build -t <tagname> .
-t
signifies the tag name. you can name this whatever you want
.
indicates that the Dockerfile
is within this directory. you can change this to be the directory name that has Dockerfile
if its not in cwd
Use docker images
to view all created images.
Buildx Container
sudo pacman -S docker-buildx
docker build -t <tagname> .
Run Container
docker run -d -p 1024:1024 <tagname>
-d
run in detached mode so it runs as a daemon process
-p
signifies what host and what port it is running on
running docker ps
will show that the image is running
nc 127.0.0.1 1024
will connect to the container
docker run -d -p 1024:1024 -t <tagID>
docker run -it --privileged <tagname>
Stop Container
docker container stop <id>
Delete Image
Use docker images
to list all images then,
docker rmi -f <id>
Open Container In App
docker ps
and note down the container IDdocker exec -it <containerid> <app>
- useful to make
<app>
be/bin/sh
orpython
Alternatively:
- useful to make
docker images
and note down the container namedocker run -it <containername> /bin/sh
. Note if you want programs like Vim, you must install it in your docker-file
Practical Use Cases
- Make a Docker Compose file which automates the process of creating gitlab servers
- You can use docker like a linux server where you SSH into