Docker compose 睡眠不在docker compose命令上工作,失败5次

Docker compose 睡眠不在docker compose命令上工作,失败5次,docker-compose,Docker Compose,我有一个阿尔卑斯山的形象。我正试图在docker compose命令行上睡觉(用于测试一些东西)。然而,这样做: 命令:sleep 30s&&NODE\u ENV=production NODE app.js 给我一个错误: thesailsapp_1 | sleep: invalid number '&&' thesailsapp_1 | sleep: invalid number '&&' thesailsapp_1 | sleep: invalid n

我有一个阿尔卑斯山的形象。我正试图在docker compose命令行上睡觉(用于测试一些东西)。然而,这样做:

命令:sleep 30s&&NODE\u ENV=production NODE app.js

给我一个错误:

thesailsapp_1  | sleep: invalid number '&&'
thesailsapp_1  | sleep: invalid number '&&'
thesailsapp_1  | sleep: invalid number '&&'
thesailsapp_1  | sleep: invalid number '&&'
thesailsapp_1  | sleep: invalid number '&&'
nginx-certbot_thesailsapp_1 exited with code 1
有人知道如何解决这个问题吗?有人知道为什么它会出错5次而不是一次吗?(在这里学习docker)

这是我的完整docker撰写文件:

version: '3'

services:
  thesailsapp:
    image: noitidart/private-container:thesailsapp
    restart: always
    environment:
      - sails_log__level=silly
    command: sleep 30s && NODE_ENV=production node app.js
  nginx:
    image: nginx:1.15-alpine
    restart: always
    volumes:
      - ./data/nginx:/etc/nginx/conf.d
      - ./data/certbot/conf:/etc/letsencrypt
      - ./data/certbot/www:/var/www/certbot
    ports:
      - 80:80
      - 443:443
    command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
  certbot:
    image: certbot/certbot
    restart: always
    volumes:
      - ./data/certbot/conf:/etc/letsencrypt
      - ./data/certbot/www:/var/www/certbot
    entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
这是我的dockerfile:

# Start with a node 8.16 slim image to keep the container size down
FROM node:12-alpine

# Specify a default directory for where our app will be placed within the container.
#
# This can be overridden with docker build --build-arg WORKDIR=some-dir/ .
# Always append the directory name with a /
ARG WORKDIR=/opt/apps/thesailsapp/

# Create a directory to contain our application
RUN mkdir -p $WORKDIR

# Switch default working directory to our new directory
WORKDIR $WORKDIR

# Copy our package and lock files over first,
# as the build can then cache this step seperately from our code.
#
# This allows us to build faster when we only have code changes,
# as the install step will be loaded from cache,
# and rebuilt when package files change
COPY package.json package-lock.json $WORKDIR

# Set NODE_ENV=development as i need the webpack dev files

# Install all deps, including development deps, as that is needed
# for the webpack build phase. Uninstall puppeteer first though,
# that's a massive install and not used for building.
RUN NODE_ENV=production npm i

# Now copy over your actual source code
#
# REMEMBER: We are ignoring node_modules in the .dockerignore file explicitly,
# so docker will not copy over that directory. The app will use th modules installed above.
COPY . $WORKDIR

# Build frontend production assets
RUN NODE_ENV=production npx webpack --config webpack.config.js

EXPOSE 1337

### why is npm start here? this should only happen on the droplet instance
# Set the default CMD to run when starting this image.
#
# You can easily override this when running the image
CMD npm start

docker compose.yml
文件中的
命令应为单个命令。如果需要多个命令,则单个命令可以是一个shell,其中实际命令作为参数

command: sh -c "sleep 30s && NODE_ENV=production node app.js"

您已经在多个其他地方这样做了,所以我猜构造很熟悉。

错误消息看起来您的代码实际上有
sleep'&&
,但我猜真正的解释是
Dockerfile
中的
CMD
声明中的语法错误。但是,我们不能排除我们看不到的问题。请你的问题告诉我们。@tripleee谢谢-我添加了docker compose和Dockerfile。然而,我认为docker compose的
命令应该覆盖Dockerfile中的命令?