简体   繁体   English

Docker在生产中撰写

[英]Docker Compose In Production

Trying to use docker-compose to build and up a simple Node.js application. 尝试使用docker-compose构建和建立一个简单的Node.js应用程序。 Although I ran into the same problem with a Django application so I think I'm just missing some sort of vital step. 尽管我在Django应用程序中遇到了同样的问题,所以我认为我只是缺少了一些至关重要的步骤。 Here is my Dockerfile: 这是我的Dockerfile:

FROM node:4.2.1
CMD mkdir -p /var/app
COPY . /var/app
EXPOSE 3000
CMD node /var/app/index.js

When I run docker compose up pointed towards a digital ocean machine it throws a node error suggesting it can't find the code in /var/app. 当我运行docker compose up指向一台数字海洋机器时,它抛出一个节点错误,提示它在/ var / app中找不到代码。 Is there some other mechanism I am supposed to use to get my code onto the machine other than docker? 除了docker之外,还有其他机制可用于将我的代码添加到计算机上吗?

The line CMD mkdir -p /var/app is wrong. CMD mkdir -p /var/app是错误的。 It should be only one CMD in a Dockerfile, usually at the end. 通常,它只能是Dockerfile中的一个CMD

Only the last CMD directive in a chain of inherited docker images will be executed. 仅执行继承的docker映像链中的最后一个CMD指令。

You should use RUN instead 您应该改用RUN

From Dockerfile reference 来自Dockerfile参考

There can only be one CMD instruction in a Dockerfile. Dockerfile中只能有一条CMD指令。 If you list more than one CMD then only the last CMD will take effect. 如果您列出多个CMD,则只有最后一个CMD才会生效。

The main purpose of a CMD is to provide defaults for an executing container. CMD的主要目的是为执行中的容器提供默认值。

Try taking out the mkdir step. 尝试执行mkdir步骤。 You also need to set the working directory. 您还需要设置工作目录。

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

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