出什么事啦?这是一个教自己的小项目,码头工人。这个Docker设置工作,健康检查通过的应用程序和mysql,应用程序是初始化和侦听如预期,我正在寻找的是一个反馈的对接-撰写和Dockerfile部分。
FROM python:3-alpine3.16
ENV FLASK_APP=app
ENV FLASK_ENV=development
# The EXPOSE instruction indicates the ports on which a container
# will listen for connections
EXPOSE 8080
# Sets the working directory for following COPY and CMD instructions
# Notice we haven’t created a directory by this name - this instruction
# creates a directory with this name if it doesn’t exist
WORKDIR /app
# Update Python
RUN python3 -m pip install --upgrade pip setuptools wheel; \
apk add --no-cache curl
# Install any needed packages specified in requirements.txt
COPY ./app/requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir -r /app/requirements.txt
COPY ./app/app.py /app/app.py
# the INTERNAL port of the app, inside the container
ENV INTERNAL_APP_PORT=8080
HEALTHCHECK --timeout=2s CMD curl --fail http://localhost:${INTERNAL_APP_PORT}/health || exit 1
ENTRYPOINT [ "python3", "app.py" ]version: "3.7"
services:
app:
platform: linux/amd64
build: .
links:
- db
ports:
- "${EXTERNAL_APP_PORT:-8080}:8080"
depends_on:
db:
condition: service_healthy
volumes:
- /usr/share/billing_app/:/app/in
db:
platform: linux/amd64
image: mysql:8
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: billdb
MYSQL_USER: billdb_owner
MYSQL_PASSWORD: password
volumes:
- ./db:/docker-entrypoint-initdb.d/
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
retries: 10谢谢
发布于 2022-06-22 15:52:30
这不是一个完整的回顾,只是我知道的事情。
您的项目是为了学习如何使用Docker。出于任何其他原因,我永远不会将生产数据库放入容器中。容器是短暂的,如果它们不再存在,应用程序就不会受到影响。数据库不是短暂的,需要持续存在,否则应用程序(可能)就会停止工作。在一些非常特殊的场景中,容器中的数据库可能是有意义的,但通常只有当数据存储在另一个数据库无法工作时,另一个数据库可以使用的单独分区上。
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
retries: 10这将检查数据库服务器是否已启动,而不是数据库服务器上的数据库是否可访问。因此,当应用程序启动时,数据库可能无法访问。
我更愿意检查数据库是否像三段式在Docker-组合检查mysql连接是否准备就绪中那样工作。
healthcheck:
test: "/usr/bin/mysql --user=root --password=rootpasswd --execute \"SHOW DATABASES;\""
timeout: 20s
retries: 10您正在使用长语法进行依赖关系管理
depends_on:
db:
condition: service_healthy有一个较短语法,它做得更少,但在这种情况下就足够了:
depends_on:
- db您的秘密是纯文本,这使它们更容易被访问。这些文件应该存储在版本控制上,这是另一种泄露纯文本秘密的方法。
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: billdb
MYSQL_USER: billdb_owner
MYSQL_PASSWORD: password始终存储加密的机密以防止未经授权的访问。。Docker有你应该喜欢的访问秘密的语法。更好的做法是利用秘密管理服务,而不是将秘密与容器一起部署,但这可能会对学习有一点影响。
https://codereview.stackexchange.com/questions/277521
复制相似问题