问题描述
你好,我正在尝试创建一个postgres组成docker
pg admin 4
和node
Hello i'm trying to create a postgres compose dockerpg admin 4and node
但是我遇到了困难,我无法创建我的服务器:
but I'm having difficulties and I can't create my server:
我尝试了所有可能的名称,但我没有不知道我做错了什么:
I've tried with all possible names and I don't know what I'm wrong:
我的 docker compose:
version: "3.7"
services:
emasa-postgres:
image: postgres
environment:
POSTGRES_PASSWORD: emasa@
POSTGRES_USER: postgres
POSTGRES_DB: emasa
volumes:
- ./pgdata:/var/lib/postgresql/data
ports:
- "5432:5432"
networks:
- postgres-compose-network
web:
image: emasa-web
depends_on:
- emasa-postgres
ports:
- "4000:4000"
networks:
- postgres-compose-network
teste-pgadmin-compose:
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: "emasa@hotmail.com"
PGADMIN_DEFAULT_PASSWORD: "emasa"
ports:
- "16543:80"
depends_on:
- emasa-postgres
networks:
- postgres-compose-network
networks:
postgres-compose-network:
driver: bridge
DockerFile :
FROM node as builder
WORKDIR usr/app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM node
WORKDIR usr/app
COPY package*.json ./
RUN npm install --production
COPY --from=builder /usr/app/dist ./dist
COPY ormconfig.docker.json ./ormconfig.json
COPY .env .
expose 4000
CMD node dist/src/index.js
我的orm config:
my orm config:
{
"type": "postgres",
"host": "db",
"port": 5432,
"username": "postgres",
"password": "emasa@",
"database": "postgres",
"synchronize": true,
"logging": false,
"entities": ["src/entity/**/*.ts"],
"migrations": ["src/migration/**/*.ts"],
"subscribers": ["src/subscriber/**/*.ts"],
"cli": {
"entitiesDir": "src/entity",
"migrationsDir": "src/migration",
"subscribersDir": "src/subscriber"
}
}
我的docker-compose记录器:
my docker-compose loggers:
Attaching to back-end_web_1, back-end_emasa-postgres_1, back-end_teste-pgadmin-compose_1
emasa-postgres_1 | The files belonging to this database system will be owned by user "postgres".
emasa-postgres_1 | This user must also own the server process.
emasa-postgres_1 |
emasa-postgres_1 | The database cluster will be initialized with locale "en_US.utf8".
emasa-postgres_1 | The default database encoding has accordingly been set to "UTF8".
emasa-postgres_1 | The default text search configuration will be set to "english".
emasa-postgres_1 |
emasa-postgres_1 | Data page checksums are disabled.
emasa-postgres_1 |
emasa-postgres_1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok
emasa-postgres_1 | creating subdirectories ... ok
emasa-postgres_1 | selecting dynamic shared memory implementation ... posix
emasa-postgres_1 | selecting default max_connections ... 20
emasa-postgres_1 | selecting default shared_buffers ... 400kB
emasa-postgres_1 | selecting default time zone ... Etc/UTC
emasa-postgres_1 | creating configuration files ... ok
emasa-postgres_1 | 2020-03-17 23:48:08.890 UTC [81] FATAL: data directory "/var/lib/postgresql/data" has wrong ownership
emasa-postgres_1 | 2020-03-17 23:48:08.890 UTC [81] HINT: The server must be started by the user that owns the data directory.
emasa-postgres_1 | child process exited with exit code 1
emasa-postgres_1 | initdb: removing contents of data directory "/var/lib/postgresql/data"
emasa-postgres_1 | running bootstrap script ... web_1 | Error: getaddrinfo ENOTFOUND db
我的容器ls:
docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3a20bcd4f105 emasa-web "docker-entrypoint.s…" 5 minutes ago Up 5 minutes 0.0.0.0:4000->4000/tcp back-end_web_1
b377e650e772 dpage/pgadmin4 "/entrypoint.sh" 14 minutes ago Up 14 minutes 443/tcp, 0.0.0.0:16543->80/tcp back-end_teste-pgadmin-compose_1
[![在此处输入图片描述] [2]] [2]
[![enter image description here][2]][2]
我确实尝试使用容器名称:
I've really tried with the container names:
emasa-postgres_1
emasa-postgres
emasa-postgres_1emasa-postgres
,但无济于事
推荐答案
可以在您提供的日志中看到问题的原因。
The cause of the problem can be seen in the log that you provided.
您可能正在Windows上运行docker机?如果是这样,这似乎是一个常见的错误-。因此,您可能想使用永久性的docker卷,而不是la
You are probably running the docker on a Windows machine? If so, it seems to be a common bug - check here. So, you might want to use a persistent docker volume instead, a la
services:
emasa-postgres:
...
volumes:
- pgdata:/var/lib/postgresql/data
networks:
- postgres-compose-network
volumes:
pgdata:
为了连接到您的来自
,您可以为 pgadmin
的emasa-postgres emasa-postgres 这样的容器:
In order to connect to your
emasa-postgres
from pgadmin
, you can set the hostname and network alias for the emasa-postgres
container like so:
services:
emasa-postgres:
hostname: my_super_cool_postgres
image: postgres
networks:
postgres-compose-network:
aliases:
- my_super_cool_postgres
而不是使用
localhost
或 db
之后,您应该能够通过主机 my_super_cool_postgres
连接到数据库。
Instead of using
localhost
or db
you should then be able to connect to the database via the host my_super_cool_postgres
.
这样,您应该可以从pgadmin连接到postgres容器。如果仍然无法使用,您还可以尝试使用相反,这是Docker的一项传统功能,但应该可以正常工作,例如
This way, you should be able to connect to your postgres container from pgadmin. If it still doesn't work for you, you can also try using the links instead, which is a legacy feature of Docker, but should work, e.g.
services:
teste-pgadmin-compose:
image: dpage/pgadmin4
links:
- "emasa-postgres:my_super_cool_postgres"
这一次,您必须将其设置为
teste-pgadmin-compose
(或从任何需要的位置)访问 emasa-postgres
容器)。然后应该可以访问主机 my_super_cool_postgres
和端口 5432
。
This time, you have to set it for the
teste-pgadmin-compose
(or from wherever you need to access to the emasa-postgres
container). The host my_super_cool_postgres
and port 5432
should then be accessible.
这篇关于Docker-撰写我无法创建Postgress服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!