DEV Community

Cover image for Install and configure docker and Postgres on Linux
Ariel Kollross
Ariel Kollross

Posted on

Install and configure docker and Postgres on Linux

This tutorial use Ubuntu/Debian base systems. If you use another system, you can adapt.

First open your terminal and run

sudo apt update && apt install docker.io
Enter fullscreen mode Exit fullscreen mode

Now, docker is installed on your machine.

To enable and start docker services, run

sudo systemctl start docker && sudo systemctl enable docker
Enter fullscreen mode Exit fullscreen mode

If you want to stop the docker,

sudo systemctl stop docker && sudo service docker stop
Enter fullscreen mode Exit fullscreen mode

Now we're going to install Postgres docker image, for this, run the follow command on terminal:

sudo docker run --name container_name -e POSTGRES_PASSWORD=badatabse_password -p 5432:5432 -d postgres
Enter fullscreen mode Exit fullscreen mode

Note, if you already installed Postgres database in your system, the port 5432 is already booked, then you can change to another number port for example,

5434:5432

If everything goes well, docker is running in your machine.

Helpful commands

Show all docker containers running:

sudo docker ps
Enter fullscreen mode Exit fullscreen mode

Show all docker containers:

sudo docker ps -a
Enter fullscreen mode Exit fullscreen mode

Start docker container by name:

sudo docker start container_name
Enter fullscreen mode Exit fullscreen mode

Stop docker container by name:

sudo docker stop container_name
Enter fullscreen mode Exit fullscreen mode

That`s all folks!

Top comments (0)