postgresql - 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
但我只是得到错误,没有主机在听什么的......我做错了什么?
解决方案
推荐阅读
- android - 带有 Smartlook SDK 的 Firebase crashlytics 未报告崩溃
- angular - 如何将 ngModel 值绑定到 select-searchable 选项中?
- python - Python 无法从列表中删除 None 值
- macos - 是否有任何 API 可以获取 macOS 中应用程序的全盘访问信息?
- assembly - 早期的 BIOS 如何使用 CALL?(跟进)
- java - 更改语言三星 S8+
- javascript - 将 192 场比赛的赛程分成 6 场比赛的周,没有重复的团队
- angular - Angular 8:监听不可访问组件中的内部元素
- here-api - 使用heremaps MapRoute API,是否可以在地图上绘制虚线作为路线?
- elasticsearch - 为什么在弹性搜索中创建了 150 个滚动上下文?