|
|
| (15 intermediate revisions by the same user not shown) |
| Line 1: |
Line 1: |
| − | ==Postgres==
| |
| − | https://www.postgresql.org/
| |
| | | | |
| − | https://en.wikipedia.org/wiki/PostgreSQL
| |
| − |
| |
| − | PostgreSQL, often simply Postgres, is an object-relational database management system (ORDBMS) with an emphasis on extensibility and standards compliance.
| |
| − |
| |
| − |
| |
| − | <br />
| |
| − | ===Deploying PostgreSQL on a Docker Container===
| |
| − |
| |
| − |
| |
| − | <br />
| |
| − | ====Install Docker CE on Ubuntu====
| |
| − | Docker is a technology that allows us to run containers. A container is a self-contained environment. A container can contain aspecific operating system, software packages, and configuration.
| |
| − |
| |
| − | We are going to install the Docker community edition (AKA Docker CE).
| |
| − |
| |
| − | https://store.docker.com/search?type=edition&offering=community
| |
| − |
| |
| − | https://docs.docker.com/install/linux/docker-ce/ubuntu/
| |
| − |
| |
| − | Please note that you will be required to create an account. After installing Docker, you might have to restart your computer.
| |
| − |
| |
| − |
| |
| − | <br />
| |
| − | ====Postgres docker installation====
| |
| − | After installing Docker, you are going to need to download the Docker image for Postgres 9.5. You can do this using the following command:
| |
| − |
| |
| − | sudo docker pull postgres:9.5
| |
| − |
| |
| − | You can then use the following command to see the list of all the Docker images installed on your computer:
| |
| − |
| |
| − | sudo docker images
| |
| − |
| |
| − | '''Setting environment variables:'''
| |
| − | In Linux and MacIn Mac and Linux we can use the following commands in Bash to create environment variables:
| |
| − | <syntaxhighlight lang="shell">
| |
| − | export DATABASE_USER=postgres
| |
| − | export DATABASE_PASSWORD=secret
| |
| − | export DATABASE_HOST=localhost
| |
| − | export DATABASE_PORT=5432
| |
| − | export DATABASE_DB=demo
| |
| − | </syntaxhighlight>
| |
| − |
| |
| − | The Postgres 9.5 image should be displayed in the list. At this point, we need to run a Docker container. Each container is arunning instance of an image. We can have multiple containers running of a given image, but this time we will only run onecontainer because we don't need two instances of Postgres. We can create a Docker container with the Postgres image using thefollowing command:
| |
| − |
| |
| − | sudo docker run --name POSTGRES_USER -p "$DATABASE_PORT":"$DATABASE_PORT" -e POSTGRES_PASSWORD="$DATABASE_PASSWORD" -e POSTGRES_USER="$DATABASE_USER" -e POSTGRES_DB="$DATABASE_DB" -d postgres:9.5
| |
| − |
| |
| − |
| |
| − | <br />
| |
| − | ====Docker basics====
| |
| − | We have already learned how to download Docker images using the «docker pull» command and how to create a container using the «docker run» command. We will now learn about other basic Docker commands. We can use the «docker ps» command to see all the containers in our machine:
| |
| − |
| |
| − | sudo docker ps -a
| |
| − |
| |
| − | We should be able to see the Postgres container running.
| |
| − |
| |
| − | [[File:Output_of_the_dockerpa-a_command.png|1000px|thumb|center|Output of the docker pa -a command]]
| |
| − |
| |
| − | Each container and image has an associated ID that looks like the following:
| |
| − | c6f7dfc1a4c8
| |
| − |
| |
| − | We can use the following command to stop a running Docker container:
| |
| − | sudo docker stop INSERT_CONTAINER_ID_HERE
| |
| − | sudo docker stop c6f7dfc1a4c8
| |
| − |
| |
| − | Similarly, we can run a Docker container using the start command:
| |
| − | sudo docker start c6f7dfc1a4c8
| |
| − |
| |
| − | Please note that the run command is used to create a new Docker container while the start command is used to run an existingDocker container given its ID.
| |
| − |
| |
| − | We can use the following command to remove a Docker container:
| |
| − | sudo docker rm c6f7dfc1a4c8
| |
| − |
| |
| − | Please note that before you can remove a Docker container, you must stop it. The following command can be used to remove aDocker image:
| |
| − | sudo docker rmi INSERT_IMAGE_ID_HERE
| |
| − |
| |
| − | Please note that before you can remove a Docker image, you must stop and remove all its associated containers.
| |
| − |
| |
| − |
| |
| − | <br />
| |