Sign inSign up

mamarbao/postgres_uc5

By mamarbao

Updated almost 4 years ago

Image containing a replica of the database named uc_5. Based on the postgres:12 image

Image
0

219

mamarbao/postgres_uc5 repository overview

How to use this image

Start a postgres_uc5 instance

>Note: it's required to have the **.env** file with the environment variables needed.

#Using default network mode
$ docker run --name postgres_container -p 5432:5432 --env-file=.env  -d mamarbao/postgres_uc5
#Using host network mode
$ docker run --name postgres_container --env-file=.env --network host -d mamarbao/postgres_uc5 

>Note: [host network mode] The URL of database will be the hostname of local host

# Launch PGAdmin container
docker run -it \
-p 443:443/tcp -p 80:80/tcp \
-e PGADMIN_DEFAULT_EMAIL="[email protected]" \
-e PGADMIN_DEFAULT_PASSWORD="root" \
 dpage/pgadmin4:latest

# Now once it is launched, access via web
#-> http://localhost:80

If it's launched in network default mode, then we need to use the IP that docker has assigned to the container.

#Get a Docker container's IP address from the host
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container_name or id>

Or access to psql inside of container directly:

$ docker run -it --rm --network some-network postgres_uc5 psql -h some-postgres -U ingenious
psql (14.3)
Type "help" for help.

uc_5=# SELECT 1;
 ?column? 
----------
        1
(1 row)

Via docker-compose

(recommended) This method is easier to deploy, with the following example of docker-compose.yml:

version: '3.8'

services:
  db:  #Name service and host-name too
    image: mamarbao/postgres_uc5
    env_file: # It's better to use the .env file (add security)
      - .env
    ports:
      - "5432:5432" #this will be removed or replaced by "expose port", thus having the port only enabled on the internal docker-compose network.
    volumes:
      #To persist the data beyond the life of the container we configured a volume
      - postgres_data:/var/lib/postgresql/data/
    #environment: # Optional,  Not recommended
    #  - POSTGRES_USER=ingenious
    #  - POSTGRES_PASSWORD=
    #  - POSTGRES_DB=uc_5
  pgadmin:
    image: dpage/pgadmin4
    restart: always
    environment:
      PGADMIN_DEFAULT_EMAIL: [email protected]
      PGADMIN_DEFAULT_PASSWORD: root
    ports:
      - "5050:80"

volumes:
  postgres_data:

This docker-compose.yml launches a database instance and an instance with the PGAdmin service. The second service helps us to manage the database through a user interface. To achieve this:

# 1. Create and launch containers
docker-compose up -d 

# 2. Then acces via browser to http://localhost:5050
# user: [email protected]
# pass: root

# 3. In PGAgmin GUI, go to Register -> Server:
#  Connection params:
#    - Hostname/address: db (name of service written in docker-compose.yml. The ip container also valid)
#   - Databse, User and Pass :  ENV variables written in .env file or environment variables in docker-compose

Tag summary

Content type

Image

Digest

sha256:edfa827c1

Size

214.7 MB

Last updated

almost 4 years ago

docker pull mamarbao/postgres_uc5