首页 > 解决方案 > Docker 容器没有 IP,但没有设置网络标志

问题描述

我的 docker 容器没有设置网络选项,但我无法连接到它。这是我的码头文件:

FROM ubuntu:20.04
ENV DEBIAN_FRONTEND noninteractive
# Install some tools
RUN apt-get update && apt-get install -y g++ clang-7 llvm-7 python make python2.7-dev bison flex libreadline-dev zlib1g-dev perl
COPY . /psql
RUN cd /psql && ./configure --with-llvm && make -j6 && make install && cd src/ext/ && make install-postgres-bitcode
RUN useradd -ms /bin/bash postgres && mkdir /data && chown postgres /data
# postgres as admin user
USER postgres
RUN /usr/local/pgsql/bin/initdb /data
# allow remote connections
VOLUME  ["/data", "/usr/local/pgsql"]
# Set the default command to run when starting the container
EXPOSE 5432
CMD /usr/local/pgsql/bin/pg_ctl -D /data start

如果我错了,请纠正我,但现在,docker 容器应该打开端口 5432,并且 PostgreSQL 默认映射到 5432,因此,5432 上的连接应该在内部转发到 PostgreSQL,对吗?

所以要运行它,我使用这个命令:

docker run -p myContainer

但是现在如何连接到容器呢?我认为 docker 容器将在 localhost 上运行,因此我可以像这样连接到它:

./psql -h localhost -p 5432 -U postgres

但我只是得到错误,没有主机在听什么的......我做错了什么?

标签: postgresqldockerlocalhostpsql

解决方案


推荐阅读