Full-stack Web Technologies

CHAPTER 3
Quick Installation

Creating an SQLite Database

SQLite is the easiest database engine to use because it does not require installation of a server (it is just an executable), and databases are just files. Find out how to install SQLite3 in your system (in Ubuntu Linux do sudo apt install sqlite3).

Now to start working with SQLite you just have to open a terminal and type:

sqlite3 your_database.db

The extension is optional, but it helps remembering which files are databases. You can of course change the name your_database for anything you wish.

Launching a Postgres server with default options

To just launch a Postgres server with Docker (as explained in Docker Hub), just type:

docker run \
    --name my-postgres -d --rm \
    -e POSTGRES_PASSWORD=gobbledygook \
    -d postgres

This will create a new container named my-postgres (this is optional), using the postgres image (containing Postgres files and dependencies), and with a password of "gobbledygook".

To use the database, we will execute the psql program inside the container:

docker exec -it my-postgres psql -U postgres

This launches the psql binary within the running container, in interactive mode (-it), and passes -U postgres to tell the command that we want to be user postgres (which is the default one).

Launching Postgres with Docker Compose

A simple way to launch a Postgres server is the following:

  1. Create a new folder and enter it.
  2. Download docker-compose.yml and save it in the directory.
  3. Issue the command:
    docker-compose up
    

Alternatively, you can use degit, which will snapshot a repository (that is, without the .git folder), and can even just copy a subfolder:

  1. Install degit with:
    npm install -g degit
    
  2. Extract a folder from the Fullstack samples repository into the postgres folder:
    degit full-stack-bcn/samples/databases/postgres-pgadmin4 postgres
    
image