Information on how to install and use Docker.
Docker is an open-source project that automates the deployment of applications inside software containers.
Ensure you have the following:
sudo
user
- SSH:
sudo apt install openssh-server
- VSCode: download
.deb
package from this URL
Administrator
user with VSCode installed
- VSCode: download
Windows installer
package from this URL
Add the docker-ce
repo:
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
Install docker
:
sudo apt install docker-ce
sudo usermod -aG docker ${USER}
Reboot your machine:
sudo reboot
Docker Compose
is a tool that allows you to run multi-container application environments based on definitions set in a YAML file. It uses service definitions to build fully customizable environments with multiple containers that can share networks and data volumes.
mkdir -p ~/.docker/cli-plugins/
curl -SL https://github.com/docker/compose/releases/download/v2.3.3/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose
chmod +x ~/.docker/cli-plugins/docker-compose
To verify that the installation was successful, you can run:
docker compose version
You'll see output similar to this:
Docker Compose version v2.3.3
docker-compose.yml
fileTo demonstrate how to set up a docker-compose.yml
file and work with Docker Compose
, you'll create a postgres environment using the official postgres
image from Docker Hub
, the public Docker registry. This containerized environment will serve a postgres
service.
Start off by creating a new directory in your home folder, and then moving into it:
mkdir ~/docker-repo
cd ~/docker-repo
In this directory, set up an application folder to serve as the document root for your postgres environment and an running folder to serve as persistent "rundir" root:
mkdir postgres
mkdir runnning
Next, create the docker-compose.yml
file:
vi docker-compose.yml
Insert the following content in your docker-compose.yml
file:
version: '3.7'
services:
postgres:
image: postgres:11
container_name: postgres
network_mode: bridge
restart: always
ports:
- 5432:5432
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=my_password
volumes:
- /home/$USER/docker-repo/running/postgres/data:/var/lib/postgresql/data
Save and close the file.
With the docker-compose.yml
file in place, you can now execute Docker Compose
to bring your environment up. The following command will download the necessary Docker
images, create a container for the postgres service, and run the containerized environment in background mode:
docker-compose -f docker-compose.yml up -d
Docker Compose
will first look for the defined image on your local system, and if it can't locate the image it will download the image from Docker Hub
.
Your environment is now up and running in the background. To verify that the container is active, you can run:
docker ps
Go inside the container:
docker exec -it postgres /bin/bash -l
Stop, start or restart the container:
docker stop postgres
docker start postgres
docker restart postgres
Tips for Daniele
docker exec -it postgres /bin/bash -l
apt update
apt install postgis
exit
Tips for Daniele (Configure a database and dump the content from
dbexport.pgsql
)
psql -h localhost -p 5432 -U postgres
CREATE ROLE livestock WITH SUPERUSER CREATEDB CREATEROLE LOGIN ENCRYPTED PASSWORD 'happycattle';
CREATE DATABASE livestock_db;
GRANT ALL PRIVILEGES ON DATABASE livestock_db TO livestock;
\q
psql -h localhost -p 5432 -U livestock livestock_db
CREATE SCHEMA postgis;
CREATE EXTENSION postgis SCHEMA public;
\q
psql -h localhost -p 5432 -U livestock livestock_db < dbexport.pgsql
psql -h localhost -p 5432 -U livestock livestock_db
SELECT * FROM livpop ORDER BY livpop DESC LIMIT 10;
\q
Docker Desktop Installer.exe
) from Docker HubDocker Desktop Installer.exe
to run the installerDocker Desktop does not start automatically after installation. To start Docker Desktop:
Docker Desktop
in the search resultsDocker Desktop
starts after you accept the terms