Sunday, 20 October 2019

How to install Docker on Ubuntu 18.04

To install Docker on my Ubuntu 18.04 machines I followed the instructions from the Docker's website: https://docs.docker.com/install/linux/docker-ce/ubuntu/

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.3 LTS
Release: 18.04
Codename: bionic

$ sudo apt-get update

sudo apt-get install \
>     apt-transport-https \
>     ca-certificates \
>     curl \
>     gnupg-agent \
>     software-properties-common


$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
OK

$ apt-key fingerprint 0EBFCD88
pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [ unknown] Docker Release (CE deb) <docker@docker.com>
sub   rsa4096 2017-02-22 [S]

$ sudo add-apt-repository \
>    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
>    $(lsb_release -cs) \
>    stable"


$ sudo apt-get update

$ sudo apt-get install docker-ce docker-ce-cli containerd.io

sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

$ docker -v
Docker version 19.03.4, build 9013bf583a

How to run Docker as non-root user?


Your regular user has to be added to the docker group (whose members are allowed to communicate wtih Docker daemon which runs as root):

$ sudo usermod -aG docker $USER

$ newgrp docker

$ docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/



References:

https://docs.docker.com/v17.09/engine/installation/linux/linux-postinstall/

Friday, 11 October 2019

How to install Meld on Ubuntu

Meld is popular cross-platform visual diff and merge tool. It can compare files and directories.

Clone Meld repository (use HTTPS URI, not the SSH-based one unless you've set up SSH key for that repo):

$ git clone https://gitlab.gnome.org/GNOME/meld.git

Check the status of master and release branches. When I built and run the app from master, I got this error:

$ meld
Meld requires GtkSourceView 4 4.0.0 or higher.




Then I found the following comment here:
> If Meld is complaining about GtkSourceView 4, you're using master, not 3.20.1.

This means I should have checked out the release branch for the desired version:

$ cd meld/
$ git checkout meld-3-20

When I was running the installer:

$ python3 setup.py install --prefix=/usr

...I was getting errors related to missing packages:

unable to execute 'intltool-update': No such file or directory
error: command 'intltool-update' failed with exit status 1

unable to execute 'xmllint': No such file or directory
error: command 'xmllint' failed with exit status 1

unable to execute 'glib-compile-resources': No such file or directory
error: command 'glib-compile-resources' failed with exit status 1

I installed the required packages (the package needed for xmllint is libxml2-utils):

$ sudo apt update
$ sudo apt upgrade
$ sudo apt install intltool 
$ sudo apt install xmllint
E: Unable to locate package xmllint
$ sudo apt install libxml2-utils
$ glib-compile-resources --help
Command 'glib-compile-resources' not found, but can be installed with:
sudo apt install libglib2.0-dev-bin
$ sudo apt install libglib2.0-dev-bin

...and run again installer:

$ python3 setup.py install --prefix=/usr

...which now complained about permissions:

creating /usr/lib/python3/dist-packages/meld
error: could not create '/usr/lib/python3/dist-packages/meld': Permission denied

Meld was finally installed with sudo user:

$ sudo python3 setup.py install --prefix=/usr
...
running install_egg_info
Writing /usr/lib/python3/dist-packages/meld-3.21.0.egg-info

When I run it first time I got this error:

$ meld
Meld requires pygobject 3.30.0 or higher.




To install the latest version of PyGObject:

$ pip3 install PyGObject 

Installing PyGObject complained couple of times about missing packages:

No package 'glib-2.0' found
Try installing it with: 'sudo apt install libglib2.0-dev'

No package 'gobject-introspection-1.0' found
Try installing it with: 'sudo apt install libgirepository1.0-dev'

No package 'cairo' found
Try installing it with: 'sudo apt install libcairo2-dev'

Installing PyGObject was successful once I installed all missing packages:

$ sudo apt install libglib2.0-dev
$ sudo apt install libgirepository1.0-dev
$ sudo apt install libcairo2-dev
$ pip3 install pycairo

I rebuilt the app and run it again:

$ sudo python3 setup.py install --prefix=/usr
$ meld

This time it opened with no issues:


References:

Monday, 7 October 2019

What do you need to do before upgrading Postgres Docker image

If you just use the new Postgres version, it is very likely you'll get a message like this:

FATAL:  database files are incompatible with server
DETAIL:  The data directory was initialized by PostgreSQL version X, which is not compatible with this version Y

In my case, I had Postgres and pgAdmin running as services in docker-compose:

$ docker-compose pull && docker-compose up
Pulling pg_db    ... done
Pulling pg_admin ... done
Recreating postgres-demo-pg ... done
Recreating postgres-demo-pgadmin ... done
Attaching to postgres-demo-pg, postgres-demo-pgadmin
postgres-demo-pg | 2019-10-07 09:46:59.270 UTC [1] FATAL:  database files are incompatible with server
postgres-demo-pg | 2019-10-07 09:46:59.270 UTC [1] DETAIL:  The data directory was initialized by PostgreSQL version 11, which is not compatible with this version 12.0 (Debian 12.0-1.pgdg100+1).
postgres-demo-pg exited with code 1

To prevent this situation do the following:

Revert postgres version to the previous one (that matches data version, 11 in my case):

docker-compose.yml:

services:
   pg_db:
      image: posgres:11

Run postgres docker container so db loads data as usual:

$ docker-compose up

Use docker exec to dump data into file:

$ docker exec postgres-demo-pg pg_dumpall -U postgres > dump.sql

Stop db container:

$ docker-compose down

Delete old mount dir:

$ sudo rm -rf database_data/

Recreate it:

$ mkdir database_data

Copy dump file to local dir that will be mounted as Postgres data dir:

$ sudo cp dump.sql database_data/

Set postgres version to the latest one:

docker-compose.yml:

services:
   pg_db:
      image: postgres


Run docker container based on the image with the latest Postgres version:

$ docker-compose pull && docker-compose up

Load dump file into db:

$ docker exec -it postgres-demo-pg bash
root@2873483c35ac:/# cd /var/lib/postgresql/data/
root@2873483c35ac:/var/lib/postgresql/data# psql -U postgres < dump.sql
SET
...
SET
root@2873483c35ac:/var/lib/postgresql/data# exit
exit

Verify db version - that it is indeed the latest:

$ docker exec -it postgres-demo-pg bashroot@2873483c35ac:/# postgres --version
postgres (PostgreSQL) 12.0 (Debian 12.0-1.pgdg100+1)
root@2873483c35ac:/# exit
exit