Skip to content

Commit

Permalink
Merge pull request #6062 from EnterpriseDB/docs/frontpage/cleanup
Browse files Browse the repository at this point in the history
Frontpage cleanup work
  • Loading branch information
djw-m authored Sep 18, 2024
2 parents 487a9b1 + be68ae5 commit 254d50f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 42 deletions.
73 changes: 46 additions & 27 deletions advocacy_docs/dev-guides/deploy/docker.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Installing PostgreSQL in a Docker container on your local machine
navTitle: Installing PostgreSQL in a Docker container
navTitle: Docker
description: Learn how to install PostgreSQL in a Docker container on your local machine for development purposes.
deepToC: true
---
Expand All @@ -22,12 +22,12 @@ Make sure Docker is installed on your machine or download and install it from [D
* Linux: Install Docker using your distribution’s package manager. For example, on Ubuntu:

```
sudo apt update
sudo apt install docker.io
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -ag docker $USER
newgrp docker
sudo apt update
sudo apt install docker.io
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -ag docker $USER
newgrp docker
```


Expand All @@ -39,19 +39,25 @@ Open a terminal or command prompt and run the following command to pull the late
docker pull postgres
```

## Running and accessing the container’s PostgreSQL database

### Run the PostgreSQL Container:
## Running the PostgreSQL container

Run a new container with the PostgreSQL image using the following command:

```
docker run --name my_postgres -d postgres -e POSTGRES_PASSWORD=mysecretpassword -v my_pgdata:/var/lib/postgresql/data -p 5432:5432
```

#### `--name my_postgres -d postgres`
#### `--name my_postgres`

The `--name` flag tells docker to creates a new container named `my_postgres`.

#### `-d`

The `--name` flag tells docker to creates a new container named `my_postgres`, while the `-d` flag tells it to use the `postgres` image which we pulled previously. Note that if we had not pulled it, this command would automatically pull the PostgreSQL image.
The `-d` flag tells Docker to run the container in detached mode. This means the container runs in the background and does not block the terminal.

#### `postgres`

This is the name of the image to run. Docker uses this name to pull the image from Docker Hub if it is not already present on the local machine. Note that if we had not pulled it, this command would automatically pull the PostgreSQL image.

#### `-e POSTGRES_PASSWORD=mysecretpassword`

Expand All @@ -66,7 +72,7 @@ These writes are persisted outside the container in a docker volume; the command

The `-p` flag maps the container’s port 5432 to the host machine’s port 5432. Port 5432 is Postgres's default port for communications. By using this flag, it allows you to access the PostgreSQL database from your host machine.

### Verify the container is running:
## Verifying the container is running

To verify that the container is running, use the following command:

Expand All @@ -79,7 +85,7 @@ This command lists all running containers. You should see the `my_postgres` cont
You now have a persistent, locally accessible Postgres database running in a Docker container.
You can now start using it.

### Access PostgreSQL:
## Access PostgreSQL with a client

To access the PostgreSQL database, without any additional tools, you can use the following command to open a PostgreSQL prompt:

Expand All @@ -89,33 +95,29 @@ docker exec \-it my\_postgres psql \-U postgres

This logs into the Docker container and runs the `psql` command as the `postgres` user from there.

TBD: Installing the psql client on your local machine.

### Using a PostgreSQL client

The `psql` command is a powerful tool for interacting with PostgreSQL databases. You should install it on your local machine to interact with the PostgreSQL database running in the Docker container.

#### macOS:
### macOS

You can install the PostgreSQL client using Homebrew:

```
brew install libpq
```

#### Windows:
### Windows

Download the PostgreSQL client from the [official website](https://www.enterprisedb.com/downloads/postgres-postgresql-downloads).

#### Linux:
### Linux

Use your distribution’s package manager to install the PostgreSQL client. For example, on Ubuntu:

```
sudo apt-get install postgresql-client
```

#### Connecting other apps
## Connecting other apps

You can also connect other applications to the PostgreSQL database running in the Docker container. You need to provide the following connection details:

Expand All @@ -126,12 +128,12 @@ You can also connect other applications to the PostgreSQL database running in th
* Database: `postgres`

Or use the connection string:

```
postgresql://postgres:mysecretpassword@localhost:5432/postgres
```

### Verifying data persistence
```
postgresql://postgres:mysecretpassword@localhost:5432/postgres
```

## Verifying data persistence

1. Create a table and insert data.
Access the PostgreSQL instance and run the following SQL commands to create a table with columns and insert some data:
Expand Down Expand Up @@ -171,6 +173,23 @@ Or use the connection string:
If everything worked as expected, you should see the employee table with the data previously loaded still present.


## Stopping and removing the container

To stop and remove the container, use the following commands:

```
docker stop my_postgres
docker rm my_postgres
```

## Deleting the volume

To remove the volume containing the database, use the following command (after stopping and removing the container):

```
docker volume rm my_pgdata
```

## Conclusion

By following these steps, you have set up a robust local development environment for PostgreSQL using Docker. This setup ensures data persistence and provides a flexible, isolated, and consistent environment for all of your development needs.

This file was deleted.

6 changes: 0 additions & 6 deletions advocacy_docs/dev-guides/developing/index.mdx

This file was deleted.

5 changes: 2 additions & 3 deletions advocacy_docs/dev-guides/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ directoryDefaults:
navigation:
- deploy
- working
- developing
---

The EDB Postgres AI Developer Guides are all about providing you, the developer, with the information you need to accelerate your development efforts using the EDB Postgres AI platform. The guides cover a wide range of topics, from setting up your development environment to deploying Postgres and AI applications.
Expand All @@ -23,10 +22,10 @@ The EDB Postgres AI Developer Guides are all about providing you, the developer,

* [PSQL for busy developers](working/psql-for-busy-developers)

## Developing Postgres Applications
<!-- ## Developing Postgres Applications

* [Developing Postgres Applications with Python](developing/developing-postgres-applications-with-python)

-->



1 comment on commit 254d50f

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.