我有一个docker-compose文件,其中结合了nginx和一个node js应用程序。整个过程开始时,我需要运行shell命令sudo sysctl -w net.core.somaxconn=65536,但是我找不到一个清晰的示例如何执行此操作。

这是我的节点应用dockerfile:

FROM node:6.9.0

ADD . /myapi
WORKDIR /myapi

RUN npm install

EXPOSE 1337

ENTRYPOINT ["node"]
CMD ["./index.js"]

这是我的nginx dockerfile:
FROM nginx
MAINTAINER me
COPY nginx.conf /etc/nginx/nginx.conf

COPY ssl-certificates/ServerCertificate.cer /var/www/ssl/ServerCertificate.cer
COPY ssl-certificates/SSLPrivateKey.key /var/www/ssl/SSLPrivateKey.key

这是我的 docker 撰写:
version: "3"

services:
    api:
        image: myregistry/my-api:1.033
    build: ./api
    ports:
        - "1337"
    environment:
        NODE_ENV: qa
    deploy:
        replicas: 12
    networks:
        - api-network
proxy:
    image: myregistry/my-api-proxy:1.033
    build:
        context: ./nginx
        args:
            RUNNING_MODE: prod
    ulimits:
        nproc: 65535
        nofile:
            soft: 10240
            hard: 20480
    ports:
        - "80:80"
        - "443:443"
    links:
        - api
    deploy:
        replicas: 3
    networks:
        - api-network

networks:
  api-network:
      driver: overlay

一个明确的例子将不胜感激,谢谢。

最佳答案

嘿,您可以使用ENTRYPOINT,如下所示:

FROM node:6.9.0

ADD . /myapi
WORKDIR /myapi

RUN npm install

EXPOSE 1337

ENTRYPOINT "/bin/node index.js" && "sudo sysctl -w net.core.somaxconn=65536"

08-25 00:47