Azure 上的 Docker 撰写失败
我无法在 azure 上启动一个简单的测试应用程序的多容器。本质上,我想要一个持续存在的应用程序服务和数据库服务,以便我可以访问 SQLITE 数据库文件并备份/下载它们,可能使用内置的 docker 工具。我真的很高兴知道我哪里出了问题。我确实先查阅了这个网站,并看到了有关正确设置端口等的文章,但仍然没有运气。
这是相关信息。 短暂性脑缺血发作。
(1) 跟踪容器日志文件的输出:
2023-12-03T11:59:23.064Z 信息 - 拉取镜像:ankwilitas/ddm:003
2023-12-03T11:59:24.218Z INFO - 003 从 ankwilitas/ddm 拉取
2023-12-03T11:59:24.229Z信息-摘要:sha256:8e3e612a9d3d51fed11bcd44dedf6c28b0c52137d44e0bc2180451c958c50f9b 2023-12-03T11:59:24.22 9Z INFO - 状态:ankwilitas/ddm:003 的图像是最新的
2023-12-03T11:59:24.240Z INFO - 拉取镜像成功,耗时:1 秒
2023-12-03T11:59:24.247Z INFO - 启动站点容器
2023-12-03T11:59:24.247Z信息-docker运行-d -p 9469:80 --name ddmtestapp_web_0_20931625 -e WEBSITES_ENABLE_APP_SERVICE_STORAGE = false -e WEBSITE_SITE_NAME = DDMtestApp -e WEBSITE_AUTH_ENABLED = False -e WEB SITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME= ddmtestapp.azurewebsites.net -e WEBSITE_INSTANCE_ID=6dc581a871e89ead50d499457423099a1bf94aee4ac35dda377966ff7460f7c1 -e HTTP_LOGGING_ENABLED=1 ankwilitas/ddm:003
2023-12-03T11:59:24.264Z 信息 - 拉取镜像:docker.io/library/sqlite:latest
2023-12-03T11:59:25.319Z 错误 - DockerApiException:Docker API 响应状态代码 = NotFound,响应 = {“message”:“sqlite 的拉取访问被拒绝,存储库不存在或可能需要“docker 登录”:被拒绝:请求的资源访问被拒绝”}
2023-12-03T11:59:25.319Z 错误 - 拉取 docker 映像 docker.io/library/sqlite:最新失败:
2023-12-03T11:59:26.333Z 错误 - DockerApiException:Docker API 响应状态代码 = NotFound,响应 = {“message”:“sqlite 的拉取访问被拒绝,存储库不存在或可能需要“docker 登录”:被拒绝:请求的资源访问被拒绝”}
2023-12-03T11:59:26.333Z 警告 - 镜像拉取失败。如果存在,则默认为本地副本。
2023-12-03T11:59:26.334Z 错误 - 映像拉取失败:验证 docker 映像配置和凭据(如果使用私有存储库)
2023-12-03T11:59:26.334Z 错误 - 多容器单元未成功启动
2023-12-03T11:59:26.335Z 信息 - 来自 ddmtestapp_web_0_20931625 =
的容器日志2023-12-03T11:59:26.345Z 信息 - 来自 ddmtestapp_db_0_20931625 =
的容器日志2023-12-03T11:59:26.437Z 信息 - 正在停止站点 ddmtestapp,因为它在启动过程中失败。
<<< so i have defined a private repo here and provided my login creds for dockerhub... so i don't know why this still fails with sqlite:latest...
(2)部署中心设置: [![部署中心设置][1]][1]
(3) Docker 组成:
services:
web:
image: ankwilitas/ddm:003
ports:
- "5000:5000"
depends_on:
- db
db:
image: "sqlite:latest"
volumes:
- db_data:/app/db # Adjust the volume path based on your app's structure
volumes:
db_data:```
(4) Dockerfile:
```FROM python:3.7
USER root
#dir for docker:
WORKDIR /ddm
#copy requirements to workdir:
COPY requirements.txt .
#pip install
RUN pip install --upgrade pip
RUN pip install -v --no-cache-dir -r requirements.txt
#copy ALL files to workdir
COPY . .```
(5) App.py:
```from flask import Flask, render_template, request, redirect, url_for
import sqlite3
app = Flask(__name__)
app.secret_key = "tbase11"
@app.route('/')
def index():
db = sqlite3.connect("db/core/core.db")
cursor = db.cursor()
cursor.execute("SELECT welcome_message FROM service_messages")
welcome_message = cursor.fetchone()[0]
db.close()
return render_template('index.html', welcome_message=welcome_message)```
[1]: https://i.stack.imgur.com/BT1Rd.png
在尝试 Docker 配置时,我遇到了相同的错误,并在 Docker 文件中进行了更改。
/
) 处理 GET 和 POST 请求。index.html
模板。文件夹 结构。from flask import Flask, render_template, request
import sqlite3
app = Flask(__name__)
def create_table():
conn = sqlite3.connect('users.db')
c = conn.cursor()
c.execute('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL)')
conn.commit()
conn.close()
def insert_user(name):
conn = sqlite3.connect('users.db')
c = conn.cursor()
c.execute('INSERT INTO users (name) VALUES (?)', (name,))
conn.commit()
conn.close()
def get_users():
conn = sqlite3.connect('users.db')
c = conn.cursor()
c.execute('SELECT name FROM users')
users = [row[0] for row in c.fetchall()]
conn.close()
return users
@app.route('/', methods=['GET', 'POST'])
def home():
create_table()
if request.method == 'POST':
user_name = request.form['name']
if user_name:
insert_user(user_name)
users = get_users()
return render_template('index.html', users=users)
if __name__ == '__main__':
app.run(debug=True)
<body>
<h1>Welcome to the Flask App</h1>
<p>This app uses Python, Flask, and SQLite. Gunicorn is used as the HTTP server to run the Flask application.</p>
<form method="POST" action="/">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<input type="submit" value="Submit">
</form>
<h2>Users:</h2>
<ul>
{% for user in users %}
<li>{{ user }}</li>
{% endfor %}
</ul>
</body>
</html>
Dockerfile:
FROM python:3.8-slim
WORKDIR /app
COPY . /app
RUN pip install --trusted-host pypi.python.org -r requirements.txt
RUN pip install pipenv
EXPOSE 5000
CMD ["pipenv", "run", "gunicorn", "--bind=0.0.0.0:5000", "--reload", "app:app"]
docker-compose.yml:
version: "3.7"
services:
app:
image: python:3.9
container_name: python-flask-sqlite
environment:
- FLASK_ENV=development
- FLASK_APP=/src/app.py
- DATABASE=/src/database.db
working_dir: /src
volumes:
- ./src:/src
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost"]
interval: 30s
timeout: 10s
retries: 3
ports:
- 5000:5000
entrypoint: bash -c "apt-get update && apt-get install -y sqlite3 && pip install --upgrade pip==23.1.2 && pip install -r /src/requirements.txt && gunicorn --bind 0.0.0.0:5000 --workers 4 app:app"
需求.txt
Flask==2.3.2
Gunicorn==20.1.0
本地:
docker build --tag python-docker1 .
docker run -p 5000:5000 python-docker1
az acr login --name "ContainerRegistryName" --password "Password" --username "ContainerRegistryName"
docker images
命令用于列出所有Docker镜像docker tag
命令用于为Docker镜像创建标签。docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
docker push IMAGE_NAME
蔚蓝: