DEV Community

Shahriyar Al Mustakim Mitul
Shahriyar Al Mustakim Mitul

Posted on

Docker series (Part 12): Database upgrade with named volume

Tasks we will do are:
Image description

Let's start:

  1. First we went to dockerhub and searched for postgres

Image description

  1. After that we are going to filter from tags for 9.6.1

Image description
You may look into it

  1. We can see the volume path here

Image description

We will use it while creating the container

  1. Lets create the container
docker container run -d --name psql -v psql:/var/lib/postgresql/data postgres:9.6.1
Enter fullscreen mode Exit fullscreen mode

basically we have used -d to detach the container and get the container ID

--name is used to name the container the name "psql"

-v is used to set the volume and "psql:" is used to give it a name and "/var/lib/postgresql/data" is given to set the volume address .

after that we have used postgress:9.6.1 to use the image of "postgres" and its version is 9.6.1

Image description

  1. NOw we will monitor our container logs live
docker container logs -f psql
Enter fullscreen mode Exit fullscreen mode

-f is given s we can keep watching as it runs

Image description

Image description

Now we can see that

LOG:  autovacuum launcher started
LOG:  database system is ready to accept connections

Enter fullscreen mode Exit fullscreen mode

That means we are ready to work

Image description

Now, lets stop it using Ctrl+c

  1. Lets stop this container
docker container stop psql
Enter fullscreen mode Exit fullscreen mode

Image description
We have used the container name here (psql)

  1. Now lets create a container having version 9.6.2
docker container run -d --name psql-2 -v psql:/var/lib/postgresql/data postgres:9.6.2
Enter fullscreen mode Exit fullscreen mode

Image description

  1. Now lets see the list of containers
docker container ps -a
Enter fullscreen mode Exit fullscreen mode

to see the whole history of containers we created or are running

Image description

You can see the postgres:9.6.2 is running but postgres:9.6.1 has exited as we stopped it few moments back.

  1. Check the volume list
docker volume ls
Enter fullscreen mode Exit fullscreen mode

Image description

Here you can see "psql" volume used . Note: for the version 9.6.1 & 9.6.2 we used the same volume psql

How?
Check out this commands

docker container run -d --name psql -v psql:/var/lib/postgresql/data postgres:9.6.1
Enter fullscreen mode Exit fullscreen mode
docker container run -d --name psql-2 -v psql:/var/lib/postgresql/data postgres:9.6.2
Enter fullscreen mode Exit fullscreen mode

We have psql:/var/lib/postgresql/data both the times where "psql" was the volume name and "/var/lib/postgresql/data" was the location of the volume

OH! By the way, don't forget that we set this volume location after checking the official image's volume location

Image description

Let's check the logs for this container

docker container logs <container name or, container id>
Enter fullscreen mode Exit fullscreen mode

Image description

This time we did not see live logs...You can do it using

docker container logs -f <container name or, container id>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)