Docker series (Part 12): Database upgrade with named volume
Tags: docker
Published: 2022-07-11 08:43:32

Tasks we will do are:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wk1652nn7e5f0zr1s7r4.png)

Let's start:  
1. First we went to dockerhub and searched for postgres

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o2pjtqr0ojudsg2es04q.png)
 
2. After that we are going to filter from tags for 9.6.1

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/woxvwf5laf0o11s6grna.png)
You may look into [it](https://hub.docker.com/layers/postgres/library/postgres/9.6.1/images/sha256-4023a747a01a29f94939c41fc5c2441837d9ebc05030c2681dc47853d73978c5?context=explore
)


3. We can see the volume path here

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/niv6jzyoxzi6cc4qs706.png)

We will use it while creating the container

4. Lets create the container

```
docker container run -d --name psql -v psql:/var/lib/postgresql/data postgres:9.6.1
```
 
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kh8vdrjndah33oh9pjix.png)

5. NOw we will monitor our container logs live

```
docker container logs -f psql
```
-f is given s we can keep watching as it runs

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1dkscmalvgul0txuddey.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d0dkcg6gptc5w8w5uebq.png)
  
Now we can see that

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

```
That means we are ready to work

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3yd65300u2ngxpndnzcw.png)

Now, lets stop it using Ctrl+c

6. Lets stop this container

```
docker container stop psql
```


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/248bgs3r5es1kaifgae4.png)
We have used the container name here (psql)

7. 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
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jtzxfz75uh1rgcplxr1i.png)

8. Now lets see the list of containers 

```
docker container ps -a
```
to see the whole history of containers we created or are running

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fdizpwzh5cwr0d7idc8m.png)
 
You can see the postgres:9.6.2 is running but postgres:9.6.1 has exited as we stopped it few moments back.

9. Check the volume list

```
docker volume ls
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i2ipl0de5d5741tr9yw6.png)
 
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
```
```
docker container run -d --name psql-2 -v psql:/var/lib/postgresql/data postgres:9.6.2
```
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qih66i0khlztbmqs9vzf.png)

Let's check the logs for this container

```
docker container logs <container name or, container id>
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/48f5hly2yd15r27qwt30.png)

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

```
docker container logs -f <container name or, container id>
```