我只是从Docker和Django开始。我尝试在此处创建示例Django产品:https://docs.docker.com/compose/django
我制作了Dockerfile,Requirements.txt和docker-compose.yml。但是当我尝试使用docker-compose命令创建Django项目时,出现错误:
docker-compose run web django-admin.py startproject MyProject .
Traceback (most recent call last):
File "docker-compose", line 3, in <module>
File "compose\cli\main.py", line 64, in main
File "compose\cli\main.py", line 116, in perform_command
File "compose\cli\main.py", line 712, in run
File "compose\cli\main.py", line 1020, in run_one_off_container
File "compose\cli\main.py", line 1100, in call_docker
File "distutils\spawn.py", line 220, in find_executable
File "ntpath.py", line 85, in join
UnicodeDecodeError: 'ascii' codec can't decode byte 0xcd in position 7:
ordinal not in range(128)
Failed to execute script docker-compose
我尝试搜索相同的问题,但没有帮助。
Windows 10 Pro(如果重要,英语不是系统语言)。
我的Docker:
docker --version
Docker version 17.03.1-ce, build c6d412e
docker-compose --version
docker-compose version 1.11.2, build f963d76f
Dockerfile:
FROM python:2.7
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
requirements.txt:
Django
psycopg2
docker-compose.yml:
version: '2'
services:
db:
image: postgres
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
谢谢大家!
更新:ntpath.py,第85行的一部分,在联接中:
def join(path, *paths):
path = os.fspath(path)
if isinstance(path, bytes):
sep = b'\\'
seps = b'\\/'
colon = b':'
else:
sep = '\\'
seps = '\\/'
colon = ':'
try:
if not paths:
path[:0] + sep #23780: Ensure compatible data type even if p is null.
result_drive, result_path = splitdrive(path)
for p in map(os.fspath, paths):
p_drive, p_path = splitdrive(p)
if p_path and p_path[0] in seps:
# Second path is absolute
if p_drive or not result_drive:
result_drive = p_drive
result_path = p_path
continue
elif p_drive and p_drive != result_drive:
if p_drive.lower() != result_drive.lower():
# Different drives => ignore the first path entirely
result_drive = p_drive
result_path = p_path
continue
# Same drive in different case
result_drive = p_drive
# Second path is relative to the first
if result_path and result_path[-1] not in seps:
result_path = result_path + sep
result_path = result_path + p_path
## add separator between UNC and non-absolute path
if (result_path and result_path[0] not in seps and
result_drive and result_drive[-1:] != colon):
return result_drive + sep + result_path
return result_drive + result_path
except (TypeError, AttributeError, BytesWarning):
genericpath._check_arg_types('join', path, *paths)
raise
最佳答案
您应该在Dockerfile
的顶部设置一个可识别UTF-8的语言环境
export LANG=C.UTF-8
关于python - Docker与Django一起编写: 'ascii'编解码器无法解码位置7的字节0xcd:序数不在范围内(128),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43408830/