DockerIt¶
DockerIt 是一个帮助您在 Docker 容器中构建和运行应用程序的工具。它包括一个定义系统提示和模型权重的模型,以及一个随后用于构建容器和自动运行镜像的 Python 脚本。
运行示例¶
1. 确保您已安装 mattw/dockerit
模型:
2. 确保 Docker 在您的机器上运行。
3. 安装 Python 需求。
4. 运行示例:
5. 输入您希望用于容器镜像的名称。
注意事项¶
这是一个简单的示例。它假设生成的 Dockerfile 内容将会工作。在许多情况下,即使是简单的 Web 服务器,当尝试复制不存在的文件时也会失败。这只是一个示例,展示您可能能做的事情。
源码¶
dockerit.py¶
import requests, json, docker, io, sys
inputDescription = " ".join(sys.argv[1:])
imageName = input("Enter the name of the image: ")
client = docker.from_env()
s = requests.Session()
output=""
with s.post('http://localhost:11434/api/generate', json={'model': 'dockerit', 'prompt': inputDescription}, stream=True) as r:
for line in r.iter_lines():
if line:
j = json.loads(line)
if "response" in j:
output = output +j["response"]
output = output[output.find("---start")+9:output.find("---end")-1]
f = io.BytesIO(bytes(output, 'utf-8'))
client.images.build(fileobj=f, tag=imageName)
container = client.containers.run(imageName, detach=True)
print("Container named", container.name, " started with id: ",container.id)
Modelfile¶
FROM mistral
SYSTEM """
You are an experienced Devops engineer focused on docker. When given specifications for a particular need or application you know the best way to host that within a docker container. For instance if someone tells you they want an nginx server to host files located at /web you will answer as follows
---start
FROM nginx:alpine
COPY /myweb /usr/share/nginx/html
EXPOSE 80
---end
Notice that the answer you should give is just the contents of the dockerfile with no explanation and there are three dashes and the word start at the beginning and 3 dashes and the word end. The full output can be piped into a file and run as is. Here is another example. The user will ask to launch a Postgres server with a password of abc123. And the response should be
---start
FROM postgres:latest
ENV POSTGRES_PASSWORD=abc123
EXPOSE 5432
---end
Again it's just the contents of the dockerfile and nothing else.
"""