简体   繁体   English

带有mongod的ENTRYPOINT和CMD命令导致未知的选项错误

[英]ENTRYPOINT & CMD commands with mongod results in unknown option error

I am using multiple Dockerfiles to setup my server infrastructure. 我正在使用多个Dockerfile来设置服务器基础架构。 One of the Dockerfiles I build is a MongoDB server which will be linked to a running web server application in a later step. 我构建的Dockerfile之一是MongoDB服务器,它将在以后的步骤中链接到正在运行的Web服务器应用程序。 Currently, I have the problem when running the MongoDB server I receive following error: 当前,运行MongoDB服务器时出现问题,我收到以下错误:

"Error parsing command line: unknown option port 27017"

In my Dockerfile I have: 在我的Dockerfile中,我有:

CMD ["--port 27017", "--dbpath /data/db", "--smallfiles"]    
ENTRYPOINT ["/usr/bin/mongod"]

When I use instead of the above commands the following everything works: 当我使用上述命令而不是上面的命令时,以下所有内容均有效:

CMD /usr/bin/mongod --port 27017 --dbpath /data/db --smallfiles

I prefer the CMD - Array and ENTRYPOINT approach more but cannot figure out why I receive the error. 我更喜欢CMD-数组和ENTRYPOINT方法,但无法弄清楚为什么会收到错误。

When using the json syntax, you need to pass each argument individually. 使用json语法时,您需要单独传递每个参数。 It will consider each element as one whereas in the non-json syntax, it will be split by the shell and considered as two. 它将每个元素视为一个,而在非json语法中,它将被shell拆分并视为两个。

CMD ["--port", "27017", "--dbpath", "/data/db", "--smallfiles"] will work. CMD ["--port", "27017", "--dbpath", "/data/db", "--smallfiles"]将起作用。

Alternatively, I don't know if mongo supports it, but most softwares does, you could do this: 另外,我不知道mongo是否支持它,但是大多数软件都支持,您可以这样做:

CMD ["--port=27017", "--dbpath=/data/db", "--smallfiles"] so it will get passed as one element but will be interpreted by mongo. CMD ["--port=27017", "--dbpath=/data/db", "--smallfiles"]因此它将作为一个元素传递,但将由mongo解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM