How to properly dock-compose?

0

I need help understanding how to correctly do a docker-compose.

I created an image and called it hello-nodemon:

FROM node:latest
ENV HOME=/src/jv-agricultor
RUN mkdir -p $HOME/
WORKDIR $HOME/
ADD package* $HOME/
RUN npm install
EXPOSE 3000
ADD . $HOME/
CMD ["npm", "start"]

When I run docker run -p 3000: 3000 works perfectly. I get return in the container:

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                    NAMES
e8f8ab65f295        hello-nodemon       "npm start"         12 seconds ago      Up 10 seconds       0.0.0.0:3000->3000/tcp   lucid_fermat

But I want to use docker-compose.yml , below:

version: "3"
services:
  web:
    image: hello-nodemon
    deploy:
      replicas: 5
      resources:
        limits:
          cpus: "0.1"
          memory: 50M
      restart_policy:
        condition: on-failure
    ports:
      - "3000:3000"
    networks:
      - webnet
networks:
  webnet:

So I used the docker stack deploy -c docker-compose.yml webservice command and this generated me:

ID                  NAME                MODE                REPLICAS            IMAGE                  PORTS
y0furo1g22zs        webservice_web      replicated          5/5                 hello-nodemon:latest   *:3000->3000/tcp 

I joined my service and so it is:

ID                  NAME                IMAGE                  NODE                DESIRED STATE       CURRENT STATE           ERROR           PORTS
nbgq8ln188dm        webservice_web.1    hello-nodemon:latest   abner               Running             Running 4 minutes ago
rrxjwudtorsm        webservice_web.2    hello-nodemon:latest   abner               Running             Running 4 minutes ago
7qrz9gtd4fan        webservice_web.3    hello-nodemon:latest   abner               Running             Running 4 minutes ago
lljmj01zlya8        webservice_web.4    hello-nodemon:latest   abner               Running             Running 4 minutes ago
raqw3z0pdxqt        webservice_web.5    hello-nodemon:latest   abner               Running             Running 4 minutes ago

Only my container looks like this:

CONTAINER ID        IMAGE                  COMMAND             CREATED             STATUS              PORTS               NAMES
6daf6afadfdc        hello-nodemon:latest   "npm start"         6 minutes ago       Up 6 minutes        3000/tcp            webservice_web.1.nbgq8ln188dmz8q8qeb60scbz
2d74f8e9a728        hello-nodemon:latest   "npm start"         6 minutes ago       Up 6 minutes        3000/tcp            webservice_web.2.rrxjwudtorsm6to56t0srkzda
e3a3a039fdf9        hello-nodemon:latest   "npm start"         6 minutes ago       Up 6 minutes        3000/tcp            webservice_web.3.7qrz9gtd4fanju4zt6zx3afsf
7f08dbdf0c8d        hello-nodemon:latest   "npm start"         6 minutes ago       Up 6 minutes        3000/tcp            webservice_web.5.raqw3z0pdxqtvkmkp00bp6tve
c6ce3762d6ae        hello-nodemon:latest   "npm start"         6 minutes ago       Up 6 minutes        3000/tcp            webservice_web.4.lljmj01zlya89gvmip5z0cf6f

You can tell there is a difference in the ports when I ran using docker stack deploy , and the first time I was lifting the container manually with docker run, but not I know why. The first time ExpressJs is perfect in the browser, but using the docker-compose the browser does not respond with the page, it is in an infinite load. Help me, please!

    
asked by anonymous 14.07.2018 / 20:59

1 answer

0

Well, I asked the same question on the international stack and this answer served me well. link

    
15.07.2018 / 00:01