Why I can't connect to postgres in docker? - docker

I used docker-compose from this project. Both docker containers were launched successfully.
kshnkvn#kshnkvn-vb:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
10fafbab73dc openpoiservice_gunicorn_flask "/ops_venv/bin/gunic…" 23 minutes ago Up 22 minutes 0.0.0.0:5000->5000/tcp openpoiservice_gunicorn_flask_1
a66fe5691455 kartoza/postgis:11.0-2.5 "/bin/sh -c /docker-…" 23 minutes ago Up 22 minutes 5432/tcp openpoiservice_psql_postgis_db_1
But when trying to check the service for functionality - he could not connect to the database. I tried to do it manually:
kshnkvn#kshnkvn-vb:~$ docker exec -it 10fafbab73dc /bin/bash
root#10fafbab73dc:/deploy/app# psql -h localhost -U gis_admin-gis
psql: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
root#10fafbab73dc:/deploy/app#
Strange, checked just in case that the type of container network is the bridge:
kshnkvn#kshnkvn-vb:~$ docker network ls
NETWORK ID NAME DRIVER SCOPE
81001dac99c0 bridge bridge local
8e65fb4ef6f8 host host local
94ce4e1605ef none null local
a3f48ac3facc openpoiservice_default bridge local
e3d4286df013 openpoiservice_poi_network bridge local
Checked postgres launch logs:
kshnkvn#kshnkvn-vb:~$ docker logs a66fe5691455
Add rule to pg_hba: 0.0.0.0/0
Add rule to pg_hba: replication replicator
Setup master database
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
2020-02-08 13:50:20.675 UTC [25] LOG: listening on IPv4 address "127.0.0.1", port 5432
2020-02-08 13:50:20.683 UTC [25] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2020-02-08 13:50:20.756 UTC [37] LOG: database system was interrupted; last known up at 2020-02-08 13:35:17 UTC
2020-02-08 13:50:21.830 UTC [48] postgres#postgres FATAL: the database system is starting up
psql: FATAL: the database system is starting up
2020-02-08 13:50:22.726 UTC [37] LOG: database system was not properly shut down; automatic recovery in progress
2020-02-08 13:50:22.730 UTC [37] LOG: redo starts at 0/21CCC50
2020-02-08 13:50:22.730 UTC [37] LOG: invalid record length at 0/21CCC88: wanted 24, got 0
2020-02-08 13:50:22.730 UTC [37] LOG: redo done at 0/21CCC50
2020-02-08 13:50:22.867 UTC [25] LOG: database system is ready to accept connections
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-----------+----------+---------+---------+-----------------------
gis | gis_admin | UTF8 | C.UTF-8 | C.UTF-8 |
postgres | postgres | UTF8 | C.UTF-8 | C.UTF-8 |
template0 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
postgres ready
Setup postgres User:Password
Creating superuser gis_admin
ALTER ROLE
Creating replication user replicator
ALTER ROLE
gis db already exists
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-----------+----------+---------+---------+-----------------------
gis | gis_admin | UTF8 | C.UTF-8 | C.UTF-8 |
postgres | postgres | UTF8 | C.UTF-8 | C.UTF-8 |
template0 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
2020-02-08 13:50:24.785 UTC [25] LOG: received smart shutdown request
2020-02-08 13:50:24.799 UTC [25] LOG: background worker "logical replication launcher" (PID 58) exited with exit code 1
2020-02-08 13:50:24.801 UTC [53] LOG: shutting down
2020-02-08 13:50:24.838 UTC [25] LOG: database system is shut down
Postgres initialisation process completed .... restarting in foreground
2020-02-08 13:50:25.842 UTC [148] LOG: listening on IPv4 address "0.0.0.0", port 5432
2020-02-08 13:50:25.842 UTC [148] LOG: listening on IPv6 address "::", port 5432
2020-02-08 13:50:25.850 UTC [148] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2020-02-08 13:50:25.880 UTC [150] LOG: database system was shut down at 2020-02-08 13:50:24 UTC
2020-02-08 13:50:25.887 UTC [148] LOG: database system is ready to accept connections
It looks like the postgre started on ip 0.0.0.0
I looked at what ip are used by the docker ip addr show command. Tried to reconnect using this ip:
psql: could not connect to server: Connection refused
Is the server running on host "172.17.0.1" and accepting
TCP/IP connections on port 5432?
root#10fafbab73dc:/deploy/app# psql -h 172.17.255.255 -U gis_admin-gis
psql: could not connect to server: Connection timed out
Is the server running on host "172.17.255.255" and accepting
TCP/IP connections on port 5432?
What can I try to do to connect the script to the database?

I you are running with docker-compose.yml and want to connect postgis from your host, you need to map the port, by adding:
ports:
- "25432:25432"
within the psql_postgis_db container (in docker-compose.yml file).
Moreover, you can override the username & password with the POSTGRES_USER and POSTGRES_PASS environment variables. You can see the default username and password in the docker-compose.yml file.
version: '2.2'
volumes:
postgis-data:
services:
gunicorn_flask:
#network_mode: "host"
build: .
volumes:
- ./osm:/deploy/app/osm
- ./ops_settings_docker.yml:/deploy/app/openpoiservice/server/ops_settings.yml
- ./categories_docker.yml:/deploy/app/openpoiservice/server/categories/categories.yml
ports:
- "5000:5000"
mem_limit: 28g
networks:
- poi_network
# Don't forget to change the host name inside ops_settings_docker.yml by the one given to docker container.
# Also port should be set to 5432 (default value) inside the same file since they are on the same network
psql_postgis_db:
image: kartoza/postgis:11.0-2.5
volumes:
- postgis-data:/var/lib/postgresql
environment:
# If you need to create multiple database you can add coma separated databases eg gis,data
- POSTGRES_DB=gis
- POSTGRES_USER=gis_admin # Here it's important to keep the same name as the one configured inside ops_settings_docker.yml
- POSTGRES_PASS=admin # Here it's important to keep the same name as the one configured inside ops_settings_docker.yml
- POSTGRES_DBNAME=gis # Here it's important to keep the same name as the one configured inside ops_settings_docker.yml
- ALLOW_IP_RANGE=0.0.0.0/0
ports:
- "25432:25432"
restart: on-failure
networks:
- poi_network
networks:
poi_network:
BTW, you must have postgresql-client on your localhost if you want to connect from your host.

Related

Odoo server is not accessible when running with docker-compose

I am trying to run Odoo using docker-compose. I have followed the instructions here. I can start the Postgres and Odoo servers using Docker and access the Odoo server correctly. When I run the first 'simplest' docker-compose example, it appears to start the Postgres server correctly but after a few minutes an error message appears from the web server:
Attaching to testdocker_db_1, testdocker_web_1
db_1 |
db_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1 |
db_1 | 2022-09-01 14:54:47.015 UTC [1] LOG: starting PostgreSQL 14.5 (Debian 14.5-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
db_1 | 2022-09-01 14:54:47.016 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2022-09-01 14:54:47.016 UTC [1] LOG: listening on IPv6 address "::", port 5432
db_1 | 2022-09-01 14:54:47.021 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2022-09-01 14:54:47.027 UTC [26] LOG: database system was shut down at 2022-09-01 14:54:22 UTC
db_1 | 2022-09-01 14:54:47.033 UTC [1] LOG: database system is ready to accept connections
web_1 | Database connection failure: connection to server at "db" (172.21.0.2), port 5432 failed: Connection timed out
web_1 | Is the server running on that host and accepting TCP/IP connections?
web_1 |
testdocker_web_1 exited with code 1
The docker-compose.yml is copied exactly from the docker hub page except that I noticed I have Postgresql v14 installed so I have changed the postgres image:
version: '3.1'
services:
web:
image: odoo:15.0
depends_on:
- db
ports:
- "8069:8069"
db:
image: postgres:14
environment:
- POSTGRES_DB=postgres
- POSTGRES_PASSWORD=odoo
- POSTGRES_USER=odoo
I had installed Docker on my Linux Mint 21 system using snap. I did that because the installation instructions here didn't work on my system.
I have now been able to install the Docker Debian packages and this problem is solved.
In order to get the Debian package to install correctly,I changed:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
To:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
jammy stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Browser request hanging when running the latest Docker ColdFusion image

I installed the Docker release of ColdFusion with the following command:
docker pull eaps-docker-coldfusion.bintray.io/cf/coldfusion:latest
I then created a compose file:
version: "3.7"
services:
coldfusion:
image: eaps-docker-coldfusion.bintray.io/cf/coldfusion:latest
ports:
- "8500:8500"
networks:
coldfusion:
hostname: coldfusion
volumes:
- "~/dev/docker/projects/coldfusion/volumes/app:/app"
- "~/dev/docker/projects/coldfusion/volumes/logs:/opt/coldfusion/cfusion/logs"
environment:
acceptEULA: "YES"
password: "ColdFusion123"
enableSecureProfile: "false"
HOST_USER_ID: ${CURRENT_UID}
HOST_GROUP_ID: ${CURRENT_GID}
deploy:
replicas: 1
restart_policy:
condition: any
delay: 5s
max_attempts: 3
window: 10s
healthcheck:
test: curl --fail http://localhost:8500 || exit 1
interval: 1m
timeout: 3s
retries: 3
networks:
coldfusion:
name: coldfusion
common:
external: true
name: common
and started it with the command:
docker stack deploy --compose-file docker-compose-dev.yml coldfusion
The log shows:
stephane#stephane-pc:~/dev/docker/projects/coldfusion$ docker service logs -f coldfusion_coldfusion
coldfusion_coldfusion.1.rlhixv3jctvm#stephane-pc | Updating webroot to /app
coldfusion_coldfusion.1.rlhixv3jctvm#stephane-pc | Configuring virtual directories
coldfusion_coldfusion.1.rlhixv3jctvm#stephane-pc | Updating password
coldfusion_coldfusion.1.rlhixv3jctvm#stephane-pc | Skipping language updation
coldfusion_coldfusion.1.rlhixv3jctvm#stephane-pc | Serial Key: Not Provided
coldfusion_coldfusion.1.rlhixv3jctvm#stephane-pc | Previous Serial Key: Not Provided
coldfusion_coldfusion.1.rlhixv3jctvm#stephane-pc | Starting ColdFusion
coldfusion_coldfusion.1.rlhixv3jctvm#stephane-pc | Starting ColdFusion 2018 server ...
coldfusion_coldfusion.1.rlhixv3jctvm#stephane-pc | The ColdFusion 2018 server is starting up and will be available shortly.
coldfusion_coldfusion.1.rlhixv3jctvm#stephane-pc | ======================================================================
coldfusion_coldfusion.1.rlhixv3jctvm#stephane-pc | ColdFusion 2018 server has been started.
coldfusion_coldfusion.1.rlhixv3jctvm#stephane-pc | ColdFusion 2018 will write logs to /opt/coldfusion/cfusion/bin/../logs/coldfusion-out.log
coldfusion_coldfusion.1.rlhixv3jctvm#stephane-pc | ======================================================================
coldfusion_coldfusion.1.rlhixv3jctvm#stephane-pc | [000] Checking server startup status...
coldfusion_coldfusion.1.rlhixv3jctvm#stephane-pc | % Total % Received % Xferd Average Speed Time Time Time Current
coldfusion_coldfusion.1.rlhixv3jctvm#stephane-pc | Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
coldfusion_coldfusion.1.rlhixv3jctvm#stephane-pc | External Addons: Disabled
coldfusion_coldfusion.1.rlhixv3jctvm#stephane-pc | External Session Storage: Disabled
coldfusion_coldfusion.1.rlhixv3jctvm#stephane-pc | Skipping setup script invocation
coldfusion_coldfusion.1.rlhixv3jctvm#stephane-pc | Secure Profile: Disabled
coldfusion_coldfusion.1.rlhixv3jctvm#stephane-pc | Cleaning up setup directories
But it hangs when typing the http://localhost:8500/ request in the browser.
The log remains empty:
tail -f volumes/logs/coldfusion-out.log
I created an index.cfm page in the /app directory:
hi
<cfset firstName = "World">
Hello <cfoutput>#firstName#</cfoutput>!
This CFML tutorial was designed for
<cfif firstName eq "World">
you!
<cfelse>
the world to see.
</cfif>
UPDATE: A 200 response comes back fine when using 127.0.0.1 instead of localhost
Opening the firewall ports does not change anything to the issue:
stephane#stephane-pc:~$ sudo ufw allow from 127.0.0.0 to any port 8500;
Rules updated
stephane#stephane-pc:~$ sudo ufw allow from any to any port 8500;
Rules updated
Rules updated (v6)
My host /etc/hosts file contains the line:
127.0.0.1 localhost
The nmap command responds:
stephane#stephane-pc:~/dev/docker/projects/coldfusion$ nmap -p 8500 localhost
Starting Nmap 7.80 ( https://nmap.org ) at 2020-09-08 12:09 CEST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00038s latency).
PORT STATE SERVICE
8500/tcp open fmtp
Nmap done: 1 IP address (1 host up) scanned in 0.22 seconds
Your docker compose file shows
hostname: coldfusion
so shouldn't it be available at http://coldfusion:8500?
If it's docker compose v3, it should be
services:
dns:
hostname: 'your-domain'

docker-entrypoint.sh is being ignored

The console logs /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/tables during the build of the Docker container (see full log below). What could be the case for this considering I have the following code:
File overview
users.sql
BEGIN TRANSACTION;
CREATE TABLE users (
id serial PRIMARY KEY,
name VARCHAR(100),
email text UNIQUE NOT NULL,
entries BEGINT DEFAULT 0,
joined TIMESTAMP NOT NULL
);
COMMIT;
deploy_schemas.sql
-- Deploy fresh database tables
\i '/docker-entrypoint-initdb.d/tables/users.sql'
\i '/docker-entrypoint-initdb.d/tables/login.sql'
Dockerfile (in postgres folder)
FROM postgres:12.2
ADD /tables/ /docker-entrypoint-initdb.d/tables/
ADD deploy_schemas.sql /docker-entrypoint-initdb.d/tables/
**docker-compose.yml**
version: "3.3"
services:
# Backend API
smart-brain-app:
container_name: backend
# image: mode:14.2.0
build: ./
command: npm start
working_dir: /usr/src/smart-brain-api
environment:
POSTGRES_URI: postgres://postgres:1212#postgres:5431/smart-brain-api-db
links:
- postgres
ports:
- "3000:3000"
volumes:
- ./:/usr/src/smart-brain-api
# Postgres
postgres:
build: ./postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: 1212
POSTGRES_DB: smart-brain-api-db
POSTGRES_HOST: postgres
ports:
- "5431:5432"
Dockerfile
FROM node:14.2.0
WORKDIR /usr/src/smart-brain-api
COPY ./ ./
RUN npm install | npm audit fix
CMD ["/bin/bash"]
Complete Log
Creating smart-brain-api_postgres_1 ... done
Creating backend ... done
Attaching to smart-brain-api_postgres_1, backend
postgres_1 | The files belonging to this database system will be owned by user "postgres".
postgres_1 | This user must also own the server process.
postgres_1 |
postgres_1 | The database cluster will be initialized with locale "en_US.utf8".
postgres_1 | The default database encoding has accordingly been set to "UTF8".
postgres_1 | The default text search configuration will be set
to "english".
postgres_1 |
postgres_1 | Data page checksums are disabled.
postgres_1 |
postgres_1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok
postgres_1 | creating subdirectories ... ok
postgres_1 | selecting dynamic shared memory implementation ... posix
postgres_1 | selecting default max_connections ... 100
postgres_1 | selecting default shared_buffers ... 128MB
postgres_1 | selecting default time zone ... Etc/UTC
postgres_1 | creating configuration files ... ok
postgres_1 | running bootstrap script ... ok
backend |
backend | > node#1.0.0 start /usr/src/smart-brain-api
backend | > npx nodemon server.js
backend |
postgres_1 | performing post-bootstrap initialization ... ok
postgres_1 | syncing data to disk ... ok
postgres_1 |
postgres_1 | initdb: warning: enabling "trust" authentication for local connections
postgres_1 | You can change this by editing pg_hba.conf or using the option -A, or
postgres_1 | --auth-local and --auth-host, the next time you run initdb.
postgres_1 |
postgres_1 | Success. You can now start the database server using:
postgres_1 |
postgres_1 | pg_ctl -D /var/lib/postgresql/data -l logfile
start
postgres_1 |
postgres_1 | waiting for server to start....2020-05-10 01:31:31.548 UTC [46] LOG: starting PostgreSQL 12.2 (Debian 12.2-2.pgdg100+1)
on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
postgres_1 | 2020-05-10 01:31:31.549 UTC [46] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1 | 2020-05-10 01:31:31.565 UTC [47] LOG: database system was shut down at 2020-05-10 01:31:31 UTC
postgres_1 | 2020-05-10 01:31:31.569 UTC [46] LOG: database system is ready to accept connections
postgres_1 | done
postgres_1 | server started
postgres_1 | CREATE DATABASE
postgres_1 |
postgres_1 |
postgres_1 | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/tables
postgres_1 |
postgres_1 | 2020-05-10 01:31:31.772 UTC [46] LOG: received fast shutdown request
postgres_1 | waiting for server to shut down....2020-05-10 01:31:31.774 UTC [46] LOG: aborting any active transactions
postgres_1 | 2020-05-10 01:31:31.775 UTC [46] LOG: background
worker "logical replication launcher" (PID 53) exited with exit code 1
postgres_1 | 2020-05-10 01:31:31.778 UTC [48] LOG: shutting down
postgres_1 | 2020-05-10 01:31:31.791 UTC [46] LOG: database system is shut down
postgres_1 | done
postgres_1 | server stopped
postgres_1 |
postgres_1 | PostgreSQL init process complete; ready for start
up.
postgres_1 |
postgres_1 | 2020-05-10 01:31:31.884 UTC [1] LOG: starting PostgreSQL 12.2 (Debian 12.2-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
postgres_1 | 2020-05-10 01:31:31.884 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres_1 | 2020-05-10 01:31:31.884 UTC [1] LOG: listening on IPv6 address "::", port 5432
postgres_1 | 2020-05-10 01:31:31.894 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1 | 2020-05-10 01:31:31.910 UTC [64] LOG: database system was shut down at 2020-05-10 01:31:31 UTC
postgres_1 | 2020-05-10 01:31:31.914 UTC [1] LOG: database system is ready to accept connections

Can't connect to postgres when using docker-compose

I am new to docker and still learning how to use it,
I am trying to use docker-compose to run Django and Postgres together
and they run perfectly and the migrate done and everything, but i have a problem i cant connect into the database using pgAdmin4 to look at the database
that's my setting.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'slack',
'USER': 'username',
'PASSWORD': 'password',
'HOST': 'db',
'PORT': 5432,
}
}
and that's my docker-compose.yml
version: '3'
services:
db:
image: postgres
environment:
POSTGRES_DB: slack
POSTGRES_USER: username
POSTGRES_PASSWORD: password
web:
build: .
command: python3 manage.py runserver 0.0.0.0:8000
volumes:
- .:/slack_code
ports:
- "8000:8000"
depends_on:
- db
everything works seems to be fine :
sudo docker-compose up
slackwebapp_db_1 is up-to-date
Creating slackwebapp_web_1 ... done
Attaching to slackwebapp_db_1, slackwebapp_web_1
db_1 | The files belonging to this database system will be owned by user "postgres".
db_1 | This user must also own the server process.
db_1 |
db_1 | The database cluster will be initialized with locale "en_US.utf8".
db_1 | The default database encoding has accordingly been set to "UTF8".
db_1 | The default text search configuration will be set to "english".
db_1 |
db_1 | Data page checksums are disabled.
db_1 |
db_1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok
db_1 | creating subdirectories ... ok
db_1 | selecting default max_connections ... 100
db_1 | selecting default shared_buffers ... 128MB
db_1 | selecting dynamic shared memory implementation ... posix
db_1 | creating configuration files ... ok
db_1 | running bootstrap script ... ok
db_1 | performing post-bootstrap initialization ... ok
db_1 | syncing data to disk ... ok
db_1 |
db_1 | Success. You can now start the database server using:
db_1 |
db_1 | pg_ctl -D /var/lib/postgresql/data -l logfile start
db_1 |
db_1 |
db_1 | WARNING: enabling "trust" authentication for local connections
db_1 | You can change this by editing pg_hba.conf or using the option -A, or
db_1 | --auth-local and --auth-host, the next time you run initdb.
db_1 | waiting for server to start....2018-01-18 19:46:43.851 UTC [38] LOG: listening on IPv4 address "127.0.0.1", port 5432
db_1 | 2018-01-18 19:46:43.851 UTC [38] LOG: could not bind IPv6 address "::1": Cannot assign requested address
db_1 | 2018-01-18 19:46:43.851 UTC [38] HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
db_1 | 2018-01-18 19:46:43.853 UTC [38] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2018-01-18 19:46:43.864 UTC [39] LOG: database system was shut down at 2018-01-18 19:46:43 UTC
db_1 | 2018-01-18 19:46:43.867 UTC [38] LOG: database system is ready to accept connections
db_1 | done
db_1 | server started
db_1 | CREATE DATABASE
db_1 |
db_1 | CREATE ROLE
db_1 |
db_1 |
db_1 | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
db_1 |
db_1 | 2018-01-18 19:46:44.388 UTC [38] LOG: received fast shutdown request
db_1 | waiting for server to shut down....2018-01-18 19:46:44.389 UTC [38] LOG: aborting any active transactions
db_1 | 2018-01-18 19:46:44.390 UTC [38] LOG: worker process: logical replication launcher (PID 45) exited with exit code 1
db_1 | 2018-01-18 19:46:44.391 UTC [40] LOG: shutting down
db_1 | 2018-01-18 19:46:44.402 UTC [38] LOG: database system is shut down
db_1 | done
db_1 | server stopped
db_1 |
db_1 | PostgreSQL init process complete; ready for start up.
db_1 |
db_1 | 2018-01-18 19:46:44.501 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2018-01-18 19:46:44.501 UTC [1] LOG: listening on IPv6 address "::", port 5432
db_1 | 2018-01-18 19:46:44.502 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2018-01-18 19:46:44.514 UTC [65] LOG: database system was shut down at 2018-01-18 19:46:44 UTC
db_1 | 2018-01-18 19:46:44.518 UTC [1] LOG: database system is ready to accept connections
web_1 | Performing system checks...
web_1 |
web_1 | System check identified no issues (0 silenced).
web_1 |
web_1 | You have 14 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
web_1 | Run 'python manage.py migrate' to apply them.
web_1 | January 18, 2018 - 19:48:49
web_1 | Django version 2.0.1, using settings 'slack_webapp.settings'
web_1 | Starting development server at http://0.0.0.0:8000/
web_1 | Quit the server with CONTROL-C.
web_1 | [18/Jan/2018 19:56:03] "GET / HTTP/1.1" 200 16559
web_1 | [18/Jan/2018 19:56:03] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
web_1 | [18/Jan/2018 19:56:04] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 82564
web_1 | [18/Jan/2018 19:56:04] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 80304
web_1 | [18/Jan/2018 19:56:04] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 81348
web_1 | [18/Jan/2018 19:56:08] "GET /admin/ HTTP/1.1" 302 0
web_1 | [18/Jan/2018 19:56:09] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 1855
web_1 | [18/Jan/2018 19:56:09] "GET /static/admin/css/base.css HTTP/1.1" 200 16106
web_1 | [18/Jan/2018 19:56:09] "GET /static/admin/css/responsive.css HTTP/1.1" 200 17894
web_1 | [18/Jan/2018 19:56:09] "GET /static/admin/css/login.css HTTP/1.1" 200 1203
web_1 | [18/Jan/2018 19:58:58] "POST /admin/login/?next=/admin/ HTTP/1.1" 302 0
web_1 | [18/Jan/2018 19:58:58] "GET /admin/ HTTP/1.1" 200 2988
web_1 | [18/Jan/2018 19:58:58] "GET /static/admin/css/base.css HTTP/1.1" 304 0
web_1 | [18/Jan/2018 19:58:58] "GET /static/admin/css/dashboard.css HTTP/1.1" 200 412
web_1 | [18/Jan/2018 19:58:58] "GET /static/admin/css/responsive.css HTTP/1.1" 304 0
web_1 | [18/Jan/2018 19:58:58] "GET /static/admin/css/fonts.css HTTP/1.1" 304 0
web_1 | [18/Jan/2018 19:58:58] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 304 0
web_1 | [18/Jan/2018 19:58:58] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 304 0
web_1 | [18/Jan/2018 19:58:58] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 304 0
web_1 | [18/Jan/2018 19:58:58] "GET /static/admin/img/icon-addlink.svg HTTP/1.1" 200 331
web_1 | [18/Jan/2018 19:58:58] "GET /static/admin/img/icon-changelink.svg HTTP/1.1" 200 380
web_1 | [18/Jan/2018 19:59:05] "GET /admin/ HTTP/1.1" 200 2988
web_1 | [18/Jan/2018 19:59:07] "GET /admin/ HTTP/1.1" 200 2988
web_1 | [18/Jan/2018 19:59:11] "GET /admin/ HTTP/1.1" 200 2988
^CGracefully stopping... (press Ctrl+C again to force)
Stopping slackwebapp_web_1 ... done
Stopping slackwebapp_db_1 ... done
but still i cant connect and i don't know how to set up a password for the Postgres default user like we do in
sudo docker run --name test -e POSTGRES_PASSWORD=password -d postgres
cuz i cant do the same with docker-compose i guess, Thanks in advance.
Hostname should be name of service defined in your docker-compose.yml
This is because you're in the docker network
You cannot use localhost or 127.0.0.1 here, because pgadmin is in container, and localhost here means 'pgadmin container'.
Let's consider your case:
version: '3'
services:
db:
image: postgres
ports:
- 5432:5432
environment:
POSTGRES_DB: slack
POSTGRES_USER: snowflake
POSTGRES_PASSWORD: 1Stepclose
pgadmin:
image: chorss/docker-pgadmin4
ports:
- 5050:5050
In this case,
Hostname: db
port : 5432
user: snowflake
pass: 1Stepclose
Hope this helps :)
In order to access the postgres database from an external program you will need to mount port 5432 which is exposed by the postgres service to a port on your host.
With the following changes to your docker-compose.yml file you should be able to connect to the database using pgadmin (on localhost:5432) as well as have postgres create your user for you.
db:
image: postgres
ports:
- "5432:5432"
environment:
- POSTGRES_DB=slack
- POSTGRES_USER=snowflake
- POSTGRES_PASSWORD=1Stepclose
Edit:
I did not realize that you were trying to connect with pgadmin4 running in another docker container. The easiest way to set that up to allow pgadmin4 container to communicate with the postgres container is to add pgadmin as a service in your docker-compose.yml file. Update your docker-compose.yml file to contain the following configuration:
version: '3'
services:
db:
image: postgres
ports:
- 5432:5432
environment:
POSTGRES_DB: slack
POSTGRES_USER: snowflake
POSTGRES_PASSWORD: 1Stepclose
pgadmin:
image: chorss/docker-pgadmin4
ports:
- 5050:5050
web:
build: .
command: python3 manage.py runserver 0.0.0.0:8000
volumes:
- .:/slack_code
ports:
- "8000:8000"
depends_on:
- db
Browse to localhost:5050 > Click add new server > Enter any name > Click on connection tab > Enter db for Hostname/Address > Enter snowflake for username > Enter 1Stepclose for password > Click save
In your setting.py file you are calling the db host 'db' but in your compose output it appears to be called 'slackwebapp_db_1'. Try changing setting.py to the full name.
I have used Pycharm to control my project, and the built-in database management system in Pycharm has connected successfully, maybe it was something wrong with pgadmin4 then, i was using chorss/docker-pgadmin4 image for pgAdmin4 as i am linux so maybe it was something wrong with the image or something. thanks guys for your effort.
I looked at postgres, from which I found the git repository (according to your docker-compose, you use the latest tag). Looks like the default user name and password 'postgres' are hard-coded. You might want to try 'postgres' in settings.py for user name and password, and see if that works.

Docker Compose LAMP Database connection error

So after running docker-compose up I get the message Error establishing a database connection when visiting http://localhost:8000/
Output of docker ps -a:
➜ ~ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5a3c015efeec dockercompose_wordpress "docker-php-entryp..." 17 minutes ago Up 16 minutes 0.0.0.0:8000->80/tcp dockercompose_wordpress_1
4e46c85345d5 dockercompose_db "docker-entrypoint..." 17 minutes ago Up 16 minutes 0.0.0.0:3306->3306/tcp dockercompose_db_1
Is this right? Or should it only show one container since wordpress depends_on db?
So I am expecting to see my Wordpress site at localhost:8000.
Had imported the database making sure I sed to change all url to point to http://localhost.
Had also mounted ./html which contains my source files to container's /var/www/html.
Did I miss anything?
Folder Structure:
Folder
|
|-db
| |-Dockerfile
| |-db.sql
|
|-html
| |- (Wordpress files)
|
|-php
| |-Dockerfile
|
|-docker-composer.yml
docker-composer.yml:
version: '3'
services:
db:
build:
context: ./db
args:
MYSQL_DATABASE: coown
MYSQL_ROOT_PASSWORD: root
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: coown
MYSQL_ROOT_PASSWORD: root
wordpress:
build:
context: ./php
depends_on:
- db
ports:
- "8000:80"
volumes:
- ./html:/var/www/html
db/Dockerfile:
FROM mysql:5.7
RUN chown -R mysql:root /var/lib/mysql/
ARG MYSQL_DATABASE
ARG MYSQL_ROOT_PASSWORD
ENV MYSQL_DATABASE=$MYSQL_DATABASE
ENV MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD
ADD db.sql /etc/mysql/db.sql
RUN cp /etc/mysql/db.sql /docker-entrypoint-initdb.d
EXPOSE 3306
php/Dockerfile:
FROM php:7.0-apache
RUN docker-php-ext-install mysqli
Some output of docker-compose up:
db_1 | 2017-06-12T19:21:33.873957Z 0 [Warning] CA certificate ca.pem is self signed.
db_1 | 2017-06-12T19:21:33.875841Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
db_1 | 2017-06-12T19:21:33.876030Z 0 [Note] IPv6 is available.
db_1 | 2017-06-12T19:21:33.876088Z 0 [Note] - '::' resolves to '::';
db_1 | 2017-06-12T19:21:33.876195Z 0 [Note] Server socket created on IP: '::'.
db_1 | 2017-06-12T19:21:33.885002Z 0 [Note] InnoDB: Buffer pool(s) load completed at 170612 19:21:33
db_1 | 2017-06-12T19:21:33.902676Z 0 [Warning] 'user' entry 'root#localhost' ignored in --skip-name-resolve mode.
db_1 | 2017-06-12T19:21:33.902862Z 0 [Warning] 'user' entry 'mysql.sys#localhost' ignored in --skip-name-resolve mode.
db_1 | 2017-06-12T19:21:33.902964Z 0 [Warning] 'db' entry 'sys mysql.sys#localhost' ignored in --skip-name-resolve mode.
db_1 | 2017-06-12T19:21:33.903006Z 0 [Warning] 'proxies_priv' entry '# root#localhost' ignored in --skip-name-resolve mode.
db_1 | 2017-06-12T19:21:33.905557Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys#localhost' ignored in --skip-name-resolve mode.
db_1 | 2017-06-12T19:21:33.910940Z 0 [Note] Event Scheduler: Loaded 0 events
db_1 | 2017-06-12T19:21:33.911310Z 0 [Note] mysqld: ready for connections.
db_1 | Version: '5.7.18' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
db_1 | 2017-06-12T19:21:33.911365Z 0 [Note] Executing 'SELECT * FROM INFORMATION_SCHEMA.TABLES;' to get a list of tables using the deprecated partition engine. You may use the startup option '--disable-partition-engine-check' to skip this check.
db_1 | 2017-06-12T19:21:33.911387Z 0 [Note] Beginning of list of non-natively partitioned tables
db_1 | 2017-06-12T19:21:33.926384Z 0 [Note] End of list of non-natively partitioned tables
wordpress_1 | 172.18.0.1 - - [12/Jun/2017:19:28:39 +0000] "GET / HTTP/1.1" 500 557 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
are you using "db" host to connect PHP (Wordpress? wp-config.php?) to your database instead of the usual "localhost"?.

Resources