首页 > 解决方案 > Dockerfile Cassandra - /usr/bin/env: 'python3\r': 没有这样的文件或目录

问题描述

我无法启动我的 cassandra 容器,当 cassandra 容器启动时出现以下错误:

/usr/bin/env: ‘python3\r’: No such file or directory

我的 Dockerfile:

FROM cassandra:3.11.6
RUN apt-get update && apt-get install -y apt-transport-https && apt-get install software-properties-common -y
COPY ["schema.cql", "wait-for-it.sh", "bootstrap-schema.py", "/"]
RUN chmod +x /bootstrap-schema.py /wait-for-it.sh
ENV BOOTSTRAPPED_SCHEMA_FILE_MARKER /bootstrapped-schema
ENV BOOTSTRAP_SCHEMA_ENTRYPOINT /bootstrap-schema.py
ENV OFFICIAL_ENTRYPOINT /docker-entrypoint.sh
# 7000: intra-node communication
# 7001: TLS intra-node communication
# 7199: JMX
# 9042: CQL
# 9160: thrift service
EXPOSE 7000 7001 7199 9042 9160
#Change entrypoint to custom script
COPY cassandra.yaml /etc/cassandra/cassandra.yaml
ENTRYPOINT ["/bootstrap-schema.py"]
CMD ["cassandra", "-Dcassandra.ignore_dc=true", "-Dcassandra.ignore_rack=true", "-f"]

仅在附加此行时才出现此错误:

ENTRYPOINT ["/bootstrap-schema.py"]

我使用 Windows 10(安装了适用于 Windows 的 Docker)。这个脚本有什么问题:bootstrap-schema.py:

#!/usr/bin/env python3

import os
import sys
import subprocess
import signal
import logging


logger = logging.getLogger('bootstrap-schema')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
logger.addHandler(ch)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)

proc_args = [os.environ['OFFICIAL_ENTRYPOINT']]
proc_args.extend(sys.argv[1:])

if (not os.path.exists(os.environ["BOOTSTRAPPED_SCHEMA_FILE_MARKER"])):
    proc = subprocess.Popen(proc_args)  # Run official entrypoint command as child process

    wait_for_cql = os.system("/wait-for-it.sh -t 120 127.0.0.1:9042")  # Wait for CQL (port 9042) to be ready
    if (wait_for_cql != 0):
        logger.error("CQL unavailable")
        exit(1)

    logger.debug("Schema creation")
    cqlsh_ret = subprocess.run("cqlsh -f /schema.cql 127.0.0.1 9042", shell=True)

    if (cqlsh_ret.returncode == 0):
        # Terminate bg process
        os.kill(proc.pid, signal.SIGTERM)
        proc.wait(20)
        # touch file marker
        open(os.environ["BOOTSTRAPPED_SCHEMA_FILE_MARKER"], "w").close()
        logger.debug("Schema created")
    else:
        logger.error("Schema creation error. {}".format(cqlsh_ret))
        exit(1)
else:
    logger.debug("Schema already exists")

os.execv(os.environ['OFFICIAL_ENTRYPOINT'], sys.argv[1:])  # Run official entrypoint

感谢任何提示

编辑

当然,我尝试添加 ex。

RUN apt-get install python3

标签: dockercassandradockerfile

解决方案


好的,我的错 - 有一个众所周知的问题 - 编码。我不得不将 windows 文件编码为 Linux 文件——每个文件,还有脚本,一切。现在效果很好:)


推荐阅读