- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我正在尝试在 docker 上设置我的项目。结构看起来像这样
Project
-- docker-compose.yml
-- docker
-- app
-- Dockerfile
-- my-project-0.1.tar.gz
-- db
-- Dockerfile
-- db_dump.dump
docker-compose 文件如下所示:
version: '3'
services:
db:
build: ./docker/db
ports:
- "5432:5432"
app:
build: ./docker/app
depends_on:
- db
command: getdatacommand
restart: always
app/Dockerfile 看起来像这样
FROM python:3
COPY myproject-0.1.tar.gz /tmp
WORKDIR /tmp
RUN pip install myproject-0.1.tar.gz
# SETUP DB ENVIROMENT VARIABLES
ENV DB_DRIVER='postgres'
ENV DB_HOST='db'
ENV DB_PORT='5432'
ENV DB_USERNAME='myuser'
ENV DB_PASSWORD='secretpass'
ENV DB_DBNAME='db-dev'
...
EXPOSE 5000
我引用了:https://docs.docker.com/engine/examples/postgresql_service/用于创建我的 postgres Dockerfile
我的数据库文件:
FROM ubuntu
# SETUP DB ENVIROMENT VARIABLES
ENV BB_DB_PORT='5432'
ENV BB_DB_USERNAME='myuser'
ENV BB_DB_PASSWORD='secretpass'
ENV BB_DB_DBNAME='db-dev'
COPY bb-dev.dump /tmp
WORKDIR /tmp
RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
RUN apt-get update && apt-get install -y python-software-properties software-properties-common postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3
USER postgres
# Start postgres create db and restore dump
RUN /etc/init.d/postgresql start &&\
psql --command psql --command "CREATE USER ${BB_DB_USERNAME} WITH SUPERUSER PASSWORD '${BB_DB_PASSWORD}';" &&\
createdb -O ${BB_DB_USERNAME} ${BB_DB_DBNAME} &&\
psql ${BB_DB_DBNAME} < bb-dev.dump
# Adjust PostgreSQL configuration so that remote connections to the
# database are possible.
RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.3/main/pg_hba.conf
# And add ``listen_addresses`` to ``/etc/postgresql/9.3/main/postgresql.conf``
RUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf
# Expose the PostgreSQL port
EXPOSE ${BB_DB_PORT}
# Set the default command to run when starting the container
CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf"]
但是,当我运行 docker-compose up
时,我收到了一个连接被拒绝错误
。事件虽然我可以像这样从主机访问 postgres 容器:
psql -h localhost -p 5432 -d db-dev -U myuser --password
我是否漏掉了一些明显的东西?
更新
为了确保数据库在应用程序开始读取之前就绪,我修改了我的 docker-compose
文件,如下所示:
version: '2.1'
services:
db:
build: ./docker/db
ports:
- "5432:5432"
healthcheck:
test: ["CMD", "pg_isready -h localhost -p 5432 -U myuser"]
interval: 30s
timeout: 10s
retries: 5
app:
build: ./docker/app
depends_on:
db:
condition: service_healthy
command: getdatacommand
restart: always
在这种情况下,应用程序容器无法启动,我收到一条消息说container is unhealthy
。但是,如果我注释掉应用程序容器并仅使用 db
容器运行 docker-compose up
最佳答案
我解决了这个问题。这与我为我的两个 Dockerfiles
使用不同的图像这一事实有关来自 ubuntu
和 来自 python3
我将应用程序容器更改为使用 from ubuntu
并安装了 python,问题就消失了。这是我修改后的 app
容器 Dockerfile
FROM ubuntu
RUN apt-get update \
&& apt-get install -y software-properties-common curl \
&& add-apt-repository ppa:jonathonf/python-3.6 \
&& apt-get remove -y software-properties-common \
&& apt autoremove -y \
&& apt-get update \
&& apt-get install -y python3.6 \
&& curl -o /tmp/get-pip.py "https://bootstrap.pypa.io/get-pip.py" \
&& python3.6 /tmp/get-pip.py \
&& apt-get remove -y curl \
&& apt autoremove -y \
&& rm -rf /var/lib/apt/lists/*
COPY myproject-0.1.tar.gz /tmp
WORKDIR /tmp
RUN pip install myproject-0.1.tar.gz
# SETUP DB ENVIROMENT VARIABLES
ENV DB_DRIVER='postgres'
ENV DB_HOST='db'
ENV DB_PORT='5432'
ENV DB_USERNAME='myuser'
ENV DB_PASSWORD='secretpass'
ENV DB_DBNAME='db-dev'
...
EXPOSE 5000
希望这对处于同样困境的人有所帮助。
关于python - Docker、postgres、sqlalchemy - 无法连接到服务器 : Cannot assign requested address,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48637148/
很难说出这里问的是什么。这个问题是模棱两可的、模糊的、不完整的、过于宽泛的或修辞的,无法以目前的形式得到合理的回答。如需帮助澄清这个问题以便重新打开它,visit the help center .
有谁知道区别吗? 最佳答案 如果您想玩可移植的可执行文件,就没有办法绕过 the specs 的副本。 . 已经有一段时间了,但如果内存正确地为我服务:IT 和 IAT 是相同的,除了 IAT 在解析
我正在尝试在 ec2-instance 上安装 Hadoop-2.6.0。 我下载并安装了 Hadoop。我还设置了环境变量。尝试启动 hdfs 服务时出现以下错误。 [ec2-user@ip-10-
我写了一个示例程序。如果我打印 pa 和 pb 的地址都是不同的。你能告诉我为什么会这样吗? #include using namespace std; class A { int x; }; cla
*&x 是否总是等于 x?如果不是,什么时候不是? &*x 是否总是等于 x?如果不是,什么时候不是? 我的猜测是 (1) 总是正确的,但 (2) 并不总是正确的,因为 x 可能并不总是一个指针,所以
我有一个 Address 类,它是一个非常简单的元数据容器。 (在底部。) 我有一个 Address 对象数组,它不是可选的 - 它肯定存在。我还有一个类维护这些引用的可选列表,如下所示: publi
我在理解 wsdl 中 soap:address 和 http:address 标签之间的区别时遇到了一些问题。它可以互换吗?我可以使用 soap:address 代替 http:address 吗?
关于AT (...) ld 的指令, this source状态: AT ( ldadr ) The expression ldadr that follows the AT keyword spec
我正在使用 Tensorflow 的 C API 在并行模拟中进行推理。因为我想要 AVX 支持,所以我从源代码编译了 Tensorflow。我链接它并使用 wmake 编译所有内容。 现在,如果我开
就像标题一样,我是cxf的新手。只是想知道 soap:address 和发布时在应用程序上下文中的 jaxws:endpoint 中指定的地址有什么区别? 此外,在jaxws:endpoint中,地址
#include #include using namespace std; class myexception: public exception { virtual const char*
C/C++ 应用程序抛出该错误,如何开始调试(比添加打印语句更好的主意)? 最佳答案 第二个地址是不是一个非常小的数字,比如 0x00000001 或 0x00000000?如果是这样,您可能只是忘记
如果我没记错的话,几天前它曾经显示“localhost”。我不确定是什么改变了 server.address().address 返回双冒号 (::) 。我在这里读到,如果它可用,它会返回一个 IPv
我现在正在使用 MPI 练习简单的并行编程。该代码旨在通过随机生成 N*N 矩阵并使用简单的邻域加权平均滤波器来模拟图像处理,而不处理第一行和最后一行和列。我在编译时没有出错,但在运行时出现了一些我无
这个问题在这里已经有了答案: How to retrieve range.address which is longer than 255 character? (2 个回答) 5年前关闭。 觉得很奇
当我尝试启动 Apache2 时收到以下消息: * Restarting web server apache2
我正在阅读一些有关指针和结构的内容,但我就是不明白:微 Controller 的头文件中有这样的内容: #define NVIC_BASE (SCS_BASE + 0x0100) /*ICER[0]
我有 alertmanager 作为 docker 容器在两台不同的主机上运行,并且两者都应该作为集群运行。两台机器都在同一个 vpc 内,并与私有(private) IP 地址通信。 我需要知道
在 Organization schema两者都有属性 address和 location . 什么时候应该使用每一个的真实世界例子? 地点 事件、组织或行动的地点。 地址 项目的物理地址。 最佳答案
我想要具有 FIFO 的服务器-客户端模型和客户端获取目录路径,但我收到错误“读:错误地址”和“写:错误地址”。 客户端 服务器错误:“读取:地址错误” 客户端错误:“写入:地址错误” 最佳答案 您可
我是一名优秀的程序员,十分优秀!