Docker
Why Docker
We will use docker because Docker makes development efficient.
The usage of docker gives a very big advantage and that’s the write once ship many.
The development team will write an application/service and use docker to make it a container that will surely have all the requirements for the user to run it on any machine that has docker installed even inside another docker container, thus giving the ability of nested virtualization
Enabling the creation of a CI/CD pipeline
|
Linux/*Nix Installation of docker
sudo -l # To ensure that we can run apt as root
sudo apt-get update # To update our repos/references on apt
sudo apt install -y lsb-release
sudo apt install -y curl
curl -V # Ensure that curl is installed and in a modern version
sudo apt install software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg # To add the gpg key on our keyring
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Add the official repo on apt or any other package manager
sudo apt install -y docker-ce # Actually installing docker
sudo usermod -aG docker $USER # Add current user to the docker group
su - ${USER} # Reload our shell
docker --version # See the docker version
docker run hello-world # Test if docker really works
Windows 10 with wsl version2 enabled
You must have wsl version2 installed and enabled (Install wsl) |
Step 1: Download the Docker Desktop for Windows from https://docs.docker.com/desktop/windows/install/
Step 2: Execute the installer via powershell or by just cklicking on the installer.exe file
cd .\Downloads\
.\"Docker Desktop Installer.exe"
Step 3: Accept anything the installer ask for
Step 4: Log out and Log in, after you are prompted to do so
Step 5: Open the docker engine app
Step 6: Go to docker app settings → Resources → WSL Integration
Step 7: Click on the refresh button
Step 8: Enable docker for the wsl installation that you want.
Step 9: Click on apply and restart
Step 10: Open the wsl shell and type:
docker --version
docker run hello-world
Set up working X11 forwarding on WSL2
Step A: Install X-Server Windows
Step B: Configure Display:
on Wsl:
export LIBGL_ALWAYS_INDIRECT=1
export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0
Remove the Windows PATH from WSL
Step A: remove paths on runtime
Add the following code to .bashrc
PATH=$(/usr/bin/printenv PATH | /usr/bin/perl -ne 'print join(":", grep { !/\/mnt\/[a-z]/ } split(/:/));')
-OR-
Alternative (run once!)
echo "export PATH=`echo $PATH | tr ':' '\n' | grep -v /mnt/ | tr '\n' ':'`" >> ~/.bashrc
Step B: Logout/Login
Fix "x509: certificate signed by unknown authority" issue
On Error:
Get https ://registry.vlabs.uniwa.gr:5080/v2/: x509: certificate
Pulling ...
ERROR: Get https://registry.vlabs.uniwa.gr:5080/v2/: x509: certificate signed by unknown authority
run
sudo su
touch set-ca.sh
copy-paste lines
registry_address=hub.swarmlab.io
registry_port=5443
mkdir -p /etc/docker/certs.d/$registry_address:$registry_port
openssl s_client -showcerts -connect $registry_address:$registry_port < /dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /etc/docker/certs.d/$registry_address:$registry_port/ca.crt
registry_port=5480
mkdir -p /etc/docker/certs.d/$registry_address:$registry_port
openssl s_client -showcerts -connect $registry_address:$registry_port < /dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /etc/docker/certs.d/$registry_address:$registry_port/ca.crt
exec file
sudo bash ./set-ca.sh
Fix "server certificate verification failed. CAfile: …"
copy-paste lines
apt-get update
apt-get upgrade
apt-get install apt-transport-https ca-certificates -y
apt-get install --reinstall ca-certificates
mkdir -p /usr/local/share/ca-certificates/swarmlab
echo -n | openssl s_client -showcerts -connect git.swarmlab.io:3000 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /usr/local/share/ca-certificates/swarmlab/ca.crt
update-ca-certificates
git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt
exec file
docker-compose
You also need to install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose