I created a docker-composer.yml file in which I added a Postgres service (v10.6). Everything goes smooth, but when I'm trying to connect ti it with the User: postgres and Password: postgres I get the following error:
psql: FATAL: password authentication failed for user "docker"
My code is:
version: '2'
services:
postgres:
container_name: "egn-postgres"
image: "postgres:10.6"
restart: always
ports:
- "${DB_PORT}:${DB_PORT}"
What can I do?
I think you forgot to put the environment variables, try this
version: '2'
services:
postgres:
container_name: "egn-postgres"
image: "postgres:10.6"
restart: always
ports:
- "${DB_PORT}:${DB_PORT}"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
As #RickoThePow says, you have to define the environment variables.
You can use the solution presented by him:
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
or use a separated file (postgres.env) with:
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=postgres
and then invoke the file in docker-compose file like:
version: '2'
services:
postgres:
container_name: "egn-postgres"
image: "postgres:10.6"
.
.
.
env_file: postgres.env
Related
I'm trying to migrate project from mysql to postgres using docker and docker compose file.
I'm connected to Linux server remotely .
My docker compose file :
version: '3.7'
services:
database:
container_name: ${PROJECT_NAME}-database
image: postgres:12
restart: unless-stopped
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: admin
POSTGRES_DB: dbtest
ports:
- "${POSTGRES_PORT}:5432"
volumes:
- ./docker/postgres/local_pgdata:/var/lib/postgresql/data
pgadmin:
image: dpage/pgadmin4
depends_on:
- database
container_name: ${PROJECT_NAME}-pgadmin4
restart: unless-stopped
ports:
- "${PGADMIN_PORT}:5454"
environment:
PGADMIN_DEFAULT_EMAIL: khaled.boussoffara-prestataire#labanquepostale.fr
PGADMIN_DEFAULT_PASSWORD: admin
PGADMIN_LISTEN_PORT: 5454
volumes:
- ./docker/pgadmin/pgadmin-data:/var/lib/pgadmin
My env file :
PROJECT_NAME=iig
PROJECT_FOLDER_NAME=sf_iig_api
HTTP_PORT=12078
HTTPS_PORT=12077
POSTGRES_PORT=12076
PGADMIN_PORT=5050
docker-compose ps :
I can't start pgadmin :
Your compose file seems okay to me, I use different ports, but my set-up is quite close to yours.
The error message recommends "check the proxy and firewall" (vérifer le proxy et le pare-feu) ... did you check it? I would use netcat:
nc -v -z RemoteHost Port
At least this could result in a helpful error message.
I have this really simple setup with a web app in one container and a Postgres service running in another container.
I need to connect to the Postgres container and thought PGHOST="db" would point to that container ..?
But I keep getting Error: getaddrinfo ENOTFOUND "db" at GetAddrInfoReqWrap.onlookup that I read as; can't find the "db" host ...
What am I missing here?
version: "3.9"
services:
web:
build: .
ports:
- "8081:3011"
links:
- db
environment:
- PGHOST="db"
- PGDATABASE="testdb"
- PGUSER="postgres"
- PGPASSWORD="postgres"
db:
image: postgres
ports:
- "5432:5432"
volumes:
- /usr/local/var/postgresql#13
Try this config. You don't need quotes when passing env variables. And it is better to use depends_on here to make sure DB is up and running before your app starts.
version: "3.9"
services:
web:
build: .
ports:
- "8081:3011"
depends_on:
- db
environment:
- PGHOST=db
- PGDATABASE=testdb
- PGUSER=postgres
- PGPASSWORD=postgres
db:
image: postgres
ports:
- "5432:5432"
volumes:
- /usr/local/var/postgresql#13
I am trying to connect a node server to a postgres database with node-postgres (pg). My docker-compose.yaml is below:
version: "3.7"
services:
server:
build:
context: ./node-boilerplate
dockerfile: Dockerfile
ports:
- '3000:3000'
depends_on:
- db
environment:
DB_USER: postgres
DB_PASSWORD: postgres
DB_DATABASE: boilerplate,
DB_HOST: db
db:
image: postgres:latest
container_name: boiler-db
ports:
- '5432:5432'
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: boilerplate
When the node app tries to access a database called boilerplate that actually exists, it gives the error:
FATAL: database "boilerplate," does not exist
However, when I connect to the postgres container (using docker exec -it <postgres_container_ID> psql -U postgres) and list databases with \l, it shows the database boilerplate listed.
What am I missing? How come the database shows up but the node server cannot find it?
Thank you in advance.
Try to docker-compose up without comma:
DB_DATABASE: boilerplate
When I try to connect my backend (using Sequelize) I get this following error:
error ConnectionRefusedError [SequelizeConnectionRefusedError]: connect ECONNREFUSED 127.0.0.1:5432
docker-compose.yml:
version: "3.7"
services:
frontend:
build:
context: ./client
dockerfile: Dockerfile
image: client
ports:
- "3000:3000"
volumes:
- ./client:/usr/src/app
backend:
build:
context: ./server
dockerfile: Dockerfile
image: server
ports:
- "8000:8000"
volumes:
- ./server:/usr/src/app
db:
image: postgres
environment:
POSTGRES_DB: ckl
POSTGRES_USER: postgres
POSTGRES_PASSWORD: docker
ports:
- "5432:5432"
What am I doing wrong ?
Thanks in advance
Assuming your backend is connecting to the db you should add a depends_on:
backend:
build:
context: ./server
dockerfile: Dockerfile
image: server
depends_on:
- db
ports:
- "8000:8000"
volumes:
- ./server:/usr/src/app
The db will now be accessible at the host db:5432 if your application is configured to connect to localhost:5432 or 172.0.0.1:5432 you'll need to replace the hostname localhost with db. Your postgres connection string might also not have a host and might be trying to connect to localhost by default. Should be able to look at sequelize to figure out how to pass a host.
I'm having a trouble on how to configure my application to integrate Flask, PonyORM, and MySQL using docker and docker-compose.
This is my .yml file:
version: '3.1'
services:
mysql:
image: mysql
restart: always
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: kofre.db
adminer:
image: adminer
restart: always
ports:
- 8080:8080
python:
build: .
volumes:
- .:/kofre-app
ports:
- 5000:5000
depends_on:
- mysql
This is my Dockerfile:
FROM python:3
ENV PYTHONBUFFERED 1
RUN mkdir /kofre-app
WORKDIR /kofre-app
COPY setup.py /kofre-app/
RUN python setup.py install
COPY . /kofre-app/
CMD [ "python", "./run.py" ]
and this is a part of my Pony initialization script:
app = Flask(__name__)
app.config.from_object('config')
db = Database()
db.bind(provider = 'mysql', host = 'mysql', user = 'root', passwd = 'root', db = 'kofre.db')
My problems:
Sometimes when I run the command docker-compose up I'm getting the message: "Can't connect to MySQL server on 'mysql' (timed out)". Is it a proble with PonyORM? Should I use another framework?
And sometimes, the mysql service seems to lock the prompt and nothing happens after that.
Could someone help me with this problems? I'd appreciate your help.
After a lot of search and tries, I finally got it working. My problem was the incorrect sintax in my docker-compose.yml in the section of the environment of the mysql container.
Now, my newer docker-compose.yml looks like this:
version: '3'
services:
python:
build: .
container_name: python
volumes:
- .:/kofre-app
ports:
- 5000:5000
links:
- mysql
adminer:
image: adminer
container_name: adminer
ports:
- 8000:8080
links:
- mysql
mysql:
image: mysql:5.6
container_name: mysql
restart: always
ports:
- 3306:3306
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=kofre.db
- MYSQL_USER=root
- MYSQL_PASSWORD=root
The answer to this problem I found here in this another answer