Docker and Portainer

Posted under » Ubuntu » Linux on 27 Apr 2024

Right now I don't have time to explain why we should be using docker but it is hard to ignore it. Install according to your specs and it has changed a lot in just months.

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

Now we install docker proper

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

At this stage you don't need sudo.

Docker containers are built from Docker images. By default, Docker pulls these images from Docker Hub. Let's test if we can pull an image.

$ service docker start
$ docker run hello-world

In some cases you have to pull the images

docker pull httpd

To look at your local images

$ docker images

To see running dockers

$ docker ps
$ docker ps -a

To start a stopped container, use docker start, followed by the container ID. To stop a running container, use docker stop, followed by the container ID or namei. Once you’ve decided you no longer need a container anymore, remove it with the docker rm.

$ docker start 1c08a7a0d0e4
$ docker stop ubuntu
$ docker rm ubuntu

Maybe this is all too hard to remember so I recommend that you docker this app called Portainer

Portainer needs persisting data (for storing user password for example). Let's create a docker volume to store this data.

$ docker volume create portainer_data
$ docker volume inspect portainer_data 

Now run it on port 9000

$ docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:2.21.4

Here is the detail of each option:

The first time Portainer starts, it asks you to set a password. The password must be at least 12 characters. Once the password is entered, you are in business.

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data