英文:
Import files in docker compose with volumes
问题
我需要在我的docker-compose项目中导入一些文件,以便能够读取并在gunicorn文件配置中使用它们。以下是我的当前docker-compose:
版本: "3.9"
服务:
db:
容器名称: my_table_postgres
镜像: postgres
端口:
- 5432/tcp
卷:
- my_table_postgres_db:/var/lib/postgresql/data
环境:
- POSTGRES_DB=my_table_postgres
- POSTGRES_USER=dev
- POSTGRES_PASSWORD=Ieyh5&RIR48!&8fc
redis:
容器名称: redis
镜像: redis
端口:
- 6739:6739/tcp
环境:
- REDIS_HOST=redis-oauth-user-service
卷:
- redis_data:/var/lib/redis/data/
my_table:
容器名称: my_table
构建: .
命令: ["python", "-m", "gunicorn", "--bind", "0.0.0.0:5000", "-c", "gunicorn.conf.py", "mytable.wsgi"]
卷:
- .:/api
- certs:/etc/letsencrypt/live/api.my-table.it
端口:
- "5000:5000"
依赖:
- db
- redis
celery:
镜像: celery
容器名称: celery
重启: unless-stopped
构建:
上下文: .
dockerfile: Dockerfile
命令: ['python', '-m', 'celery', '-A', 'mytable', 'worker', '-l', 'INFO']
卷:
- .:/api
依赖:
- redis
- my_table
链接:
- redis
nginx:
构建: ./nginx
端口:
- "8000:80"
依赖:
- my_table
卷:
my_table_postgres_db:
redis_data:
这里是我用来读取文件的代码行:
certfile = "fullchain.pem"
keyfile = "privkey.pem"
但每次运行时,都会出现以下错误:
table | client = ssl.wrap_socket(client, server_side=True,
my_table | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
my_table | File "/usr/local/lib/python3.11/ssl.py", line 1443, in wrap_socket
my_table | context.load_cert_chain(certfile, keyfile)
my_table | IsADirectoryError: [Errno 21] Is a directory
这意味着路径不正确。我该如何在docker-compose文件中和另一个文件中修复路径,以便它们能够相互匹配并使用正确的文件?
非常感谢!
英文:
I need to import a couple of files in my docker-compose project to be able to read them and use them in a gunicorn file configuration. Here is my current docker compose:
version: "3.9"
services:
db:
container_name: my_table_postgres
image: postgres
ports:
- 5432/tcp
volumes:
- my_table_postgres_db:/var/lib/postgresql/data
environment:
- POSTGRES_DB=my_table_postgres
- POSTGRES_USER=dev
- POSTGRES_PASSWORD=Ieyh5&RIR48!&8fc
redis:
container_name: redis
image: redis
ports:
- 6739:6739/tcp
environment:
- REDIS_HOST=redis-oauth-user-service
volumes:
- redis_data:/var/lib/redis/data/
my_table:
container_name: my_table
build: .
command: ["python", "-m", "gunicorn", "--bind", "0.0.0.0:5000", "-c", "gunicorn.conf.py", "mytable.wsgi"]
volumes:
- .:/api
- certs:/etc/letsencrypt/live/api.my-table.it
ports:
- "5000:5000"
depends_on:
- db
- redis
celery:
image: celery
container_name: celery
restart: unless-stopped
build:
context: .
dockerfile: Dockerfile
command: ['python', '-m', 'celery', '-A', 'mytable' ,'worker', '-l', 'INFO']
volumes:
- .:/api
depends_on:
- redis
- my_table
links:
- redis
nginx:
build: ./nginx
ports:
- "8000:80"
depends_on:
- my_table
volumes:
my_table_postgres_db:
redis_data:
And here are the lines that I am using to read the files:
certfile = "fullchain.pem"
keyfile = "privkey.pem"
But each time I run, the following error occurs:
table | client = ssl.wrap_socket(client, server_side=True,
my_table | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
my_table | File "/usr/local/lib/python3.11/ssl.py", line 1443, in wrap_socket
my_table | context.load_cert_chain(certfile, keyfile)
my_table | IsADirectoryError: [Errno 21] Is a directory
So that means that the path is incorrect. How can I fix the path in the docker compose file and also in the other file, in order to make them meet together and use the correct file?
Thank you a lot
Here is the Dockerfile as suggested from the comments:
FROM python:3.11
# Managing user
RUN useradd -ms /bin/bash devuser
USER devuser
WORKDIR /home/devuser
# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1
# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1
COPY --chown=devuser:devuser requirements.txt requirements.txt
RUN pip install --user --default-timeout=1000 --upgrade pip
RUN pip install --user --default-timeout=1000 -r requirements.txt
EXPOSE 5000
COPY --chown=devuser:devuser . .
ENTRYPOINT [ "sh", "entrypoint.sh" ]
答案1
得分: 1
不确定为什么它被报告为目录,能分享一下你的文件树吗?Dockerfile
也会有所帮助。
假设 fullchain.pem
和 privkey.pem
放在 certs
文件夹中,你需要在配置中提供这些文件的路径。由于你将 .
挂载到 /api
,你可以使用下面的配置:
certfile = "certs/fullchain.pem"
keyfile = "certs/privkey.pem"
这只有在你的容器镜像中工作目录设置为 /api
的情况下才有效。
英文:
Not sure why it's reported as a directory, can you share your file tree? The Dockerfile
will also help.
Assuming that fullchain.pem
and privkey.pem
are inside the certs
folder, you'd need to provide the path to these files in your configuration. As you're mounting .
to /api
, you can use the configuration below:
certfile = "certs/fullchain.pem"
keyfile = "certs/privkey.pem"
This again will work only if your work directory is set to /api
in your container image.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论