【问题标题】:How to resolve "FATAL CONFIG FILE ERROR"?如何解决“致命配置文件错误”?
【发布时间】:2019-06-27 10:17:51
【问题描述】:

我已经成功构建了 docker 镜像,但是当我尝试登录该镜像时,我遇到了一个问题。我正在使用 node-10.15.3、mongo-latest 和 redis-4.0.1 构建一个以 ubuntu 为基础的图像。

Dockerfile:

FROM ubuntu:14.04

RUN apt-get update
RUN apt-get install -y curl
RUN curl --silent --location https://deb.nodesource.com/setup_4.x | sudo bash -
RUN apt-get install --yes nodejs
RUN apt-get install --yes build-essential

COPY . /src

RUN cd /src
RUN npm install -g npm
#RUN npm install

EXPOSE 8080

RUN apt-get update && apt-get install -y redis-server
EXPOSE 6379

RUN apt-get update
RUN 
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 && 
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' > /etc/apt/sources.list.d/mongodb.list && 
apt-get update && 
apt-get install -y mongodb-org && 
rm -rf /var/lib/apt/lists/*

VOLUME ["/data/db"]

WORKDIR /data

EXPOSE 27017
EXPOSE 28017

ADD run.sh /run.sh
RUN chmod +x /run.sh

ENTRYPOINT ["/usr/bin/redis-server"]
#CMD ["node", "index.js"]
CMD ["/run.sh"]

run.sh 文件:

nodaemon=true

command=node index.js

command=mongod

成功构建此 Dockerfile 后,当我尝试登录该映像时,我得到以下输出: * 致命配置文件错误 * 读取配置文件,第 3 行

'command=node index.js' 指令错误或参数数量错误

【问题讨论】:

    标签: linux docker dockerfile


    【解决方案1】:

    我认为删除 ENTRYPOINT 并像这样编写 run.sh 脚本的最佳方法:

    #!/bin/bash
    cd /data
    /usr/bin/redis-server &
    mongod &
    node index.js
    

    自从在 Windows 上工作以来,这里是完整的示例:

    FROM ubuntu:14.04
    
    RUN apt-get update
    RUN apt-get install -y curl
    RUN curl --silent --location https://deb.nodesource.com/setup_4.x | sudo bash -
    RUN apt-get install --yes nodejs
    RUN apt-get install --yes build-essential
    
    COPY . /src
    
    RUN cd /src
    RUN npm install -g npm
    #RUN npm install
    
    EXPOSE 8080
    
    RUN apt-get update && apt-get install -y redis-server
    EXPOSE 6379
    
    RUN apt-get update
    RUN 
    apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 && 
    echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' > /etc/apt/sources.list.d/mongodb.list && 
    apt-get update && 
    apt-get install -y mongodb-org && 
    rm -rf /var/lib/apt/lists/*
    
    VOLUME ["/data/db"]
    
    WORKDIR /data
    
    EXPOSE 27017
    EXPOSE 28017
    
    ADD run.sh /run.sh
    RUN chmod +x /run.sh
    RUN apt-get update && apt-get install -y dos2unix && dos2unix /run.sh
    CMD ["/run.sh"]
    

    无论如何,在container 中启动多个服务是个坏主意

    【讨论】:

    • 谢谢。映像已成功构建,但是当我使用 docker run -it 登录到映像时,出现以下错误:standard_init_linux.go:207: exec 用户进程导致“exec 格式错误”
    • 当我登录到我的 docker 镜像时出现此错误:standard_init_linux.go:207: exec 用户进程导致“没有这样的文件或目录”
    • 我运行命令并得到以下错误:步骤 21/22:运行 apt-get install -y dos2unix && dos2unix run.sh ---> 在 f85ae66196d1 中运行读取包列表...构建依赖树... 读取状态信息... E: Unable to locate package dos2unix The command '/bin/sh -c apt-get install -y dos2unix && dos2unix run.sh' 返回非零码:100跨度>
    • 收到以下错误:选择以前未选择的包 dos2unix。 (正在读取数据库...当前安装的 20824 个文件和目录。) 准备解压 .../dos2unix_6.0.4-1_amd64.deb ... 解压 dos2unix (6.0.4-1) ... 设置 dos2unix (6.0.4 -1)... dos2unix:run.sh:没有这样的文件或目录 dos2unix:跳过run.sh,不是常规文件。命令 '/bin/sh -c apt-get update && apt-get install -y dos2unix && dos2unix run.sh' 返回非零代码:2
    • 但是,当我尝试登录镜像时,出现如下错误:2019-06-27T14:23:28.152+0000 [initandlisten] allocator: tcmalloc 2019-06-27T14 :23:28.152+0000 [initandlisten] 选项:{} module.js:327 throw err; ^ 错误:Function.Module._resolveFilename (module.js:325:15) at Function.Module._load (module.js:276:25) at Function.Module.runMain 找不到模块'/data/index.js' (module.js:441:10) 在启动时 (node.js:140:18) 在 node.js:1043:3
    【解决方案2】:

    这是正确的工作代码: Dockerfile:

    # Pull base image.
    FROM ubuntu:14.04
    
    # Install Node.js
    RUN apt-get update
    RUN apt-get install -y curl
    RUN curl --silent --location https://deb.nodesource.com/setup_10.x | bash -
    RUN apt-get install --yes nodejs
    RUN apt-get install --yes build-essential
    
    # Bundle angular app source
    # Trouble with COPY http://stackoverflow.com/a/30405787/2926832
    COPY . /src
    
    # Install app dependencies
    RUN cd /src
    RUN npm install -g npm
    #RUN npm install
    
    # Binds to port 8080
    EXPOSE 8080
    
    # Installing redis server
    RUN apt-get update && apt-get install -y redis-server
    EXPOSE 6379
    
    # Update the repository sources list
    RUN apt-get update
    
    # Install MongoDB.
    RUN \
        apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 && \
        echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' > /etc/apt/sources.list.d/mongodb.list && \
        apt-get update && \
        apt-get install -y mongodb-org && \
        rm -rf /var/lib/apt/lists/* && \
        cd / 
    
    COPY index.js .
    
    # Define mountable directories.
    VOLUME ["/data/db"]
    
    # Define working directory.
    WORKDIR /data
    
    # Define default command.
    #CMD ["mongod"]
    
    # Expose ports.
    #   - 27017: process
    #   - 28017: http
    EXPOSE 27017
    EXPOSE 28017
    
    ADD run.sh /run.sh
    RUN chmod +x /run.sh
    #  Defines your runtime(define default command)
    # These commands unlike RUN (they are carried out in the construction of the container) are run when the container
    #ENTRYPOINT  ["/usr/bin/redis-server"]
    #CMD ["node", "index.js"]
    RUN apt-get update && apt-get install -y dos2unix && dos2unix /run.sh
    CMD ["/run.sh"]
    

    run.sh 文件中的代码:

    #!/bin/bash
    cd /data
    /usr/bin/redis-server &
    mongod &
    node /index.js
    

    index.js 文件中的代码:

    console.log("helllllllooooo");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-12
      • 2019-07-26
      • 2015-01-11
      相关资源
      最近更新 更多