Let's start:
- First we went to dockerhub and searched for postgres
- After that we are going to filter from tags for 9.6.1
You may look into it
- We can see the volume path here
We will use it while creating the container
- 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
- NOw we will monitor our container logs live
docker container logs -f psql
-f is given s we can keep watching as it runs
Now we can see that
LOG: autovacuum launcher started
LOG: database system is ready to accept connections
That means we are ready to work
Now, lets stop it using Ctrl+c
- Lets stop this container
docker container stop psql
We have used the container name here (psql)
- 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
- Now lets see the list of containers
docker container ps -a
to see the whole history of containers we created or are running
You can see the postgres:9.6.2 is running but postgres:9.6.1 has exited as we stopped it few moments back.
- Check the volume list
docker volume ls
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
Let's check the logs for this container
docker container logs <container name or, container id>
This time we did not see live logs...You can do it using
docker container logs -f <container name or, container id>
Top comments (0)