如何解决“致命配置文件错误”?

时间:2019-06-27 10:17:51

标签: linux docker dockerfile

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

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'       错误的指令或错误的参数数量

    
  

2 个答案:

答案 0 :(得分: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

中启动多个服务是一个坏主意

答案 1 :(得分:0)

这是正确的工作代码: 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");