为了进行测试,我正在尝试在Docker容器中设置Postgres,以便我们的Python应用程序可以对其运行测试套件。
以下是我的Dockerfile:
# Set the base image to Ubuntu
FROM ubuntu:16.04
# Update the default application repository sources list
RUN apt-get update && apt-get install -y \
python2.7 \
python-pip \
python-dev \
build-essential \
libpq-dev \
libsasl2-dev \
libffi-dev \
postgresql
USER postgres
RUN /etc/init.d/postgresql start && \
psql -c "CREATE USER circle WITH SUPERUSER PASSWORD 'circle';" && \
createdb -O darwin circle_test
USER root
RUN service postgresql stop && service postgresql start
# Upgrade pip
RUN pip install --upgrade pip
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
EXPOSE 5000
# Set the container entrypoint
ENTRYPOINT ["gunicorn", "--config", "/app/config/gunicorn.py", "--access-logfile", "-", "--error-logfile", "-", "app:app"]
当我运行:
docker run --entrypoint python darwin:latest -m unittest discover -v -s test
我正在收到:
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
唯一让它正常工作的方法是ssh进入容器,重启postgres并直接运行测试套件。
这里有什么我忽略的吗?
RUN service postgresql stop && service postgresql start
在 RUN 中,而不是在 CMD 或 ENTRYPOINT 中,所以当容器启动时它被“遗忘”了。 - user2915097RUN
改为CMD
,但它仍然显示相同的错误。 - doremi