Closed jellydn closed 4 years ago
@jellydn thanks!
related: https://github.com/moleculerjs/moleculer-template-project/issues/13
No problem :) Please let me know if you guys have any feedback. Thanks.
@jellydn thanks. did you test it? It works? The localhost
a little bit strange for me because in containers the localhost
is only the given container.
Hi @icebob
did you test it?
Yes, I did. You could check their example https://docs.traefik.io/user-guides/docker-compose/basic-example/
Hey @jellydn thanks for the PR. However, I can't get things working here.
I've installed your template moleculer init jellydn/moleculer-template-project#patch-1 test
and then started the containers with npm run dc:up
They did start but I couldn't call service actions. Can you please check what's wrong and fix it?
Hello @AndreMaz
Can you please check what's wrong and fix it?
No problem. Let me recheck and fix if any issues. Thanks.
Hello, @AndreMaz My bad. I missed exposing the port on the docker file. If you try to test again, it should work.
Hm.. "expose" is not need. Traefik proxy port in labels. "Expose" needs for docker-proxy on host machine available port.
Traefik proxy
Well, I see. It should work as that way on v1. However, when I checked on their example with whoami
https://github.com/containous/whoami/blob/master/Dockerfile#L26
They did expose the port 80. That is the reason why I exposed the port when doing the migration to v2.
Hi @intech I found the reason. traefik.port
was removed on v2.
[docker] Remove traefik.port from documentation (#4886 by ldez)
Tested again. Now compose looks like this:
traefik:
image: traefik
container_name: traefik
command:
# - --log.level=DEBUG
- --api.insecure=true
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --entrypoints.web.address=:80
- traefik.http.routers.web.rule=Host(`localhost`)
- traefik.http.routers.web.entrypoints=web
labels:
- "traefik.enable=true"
- "traefik.backend=traefik"
- "traefik.port=8080"
ports:
- 3000:80
- 3001:8080
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
networks:
- internal
- default
Still can't call service actions
Well, could you tell me how did you test? Here is my testing with yarn dc:up
yarn dc:up
yarn run v1.19.1
warning package.json: No license field
$ docker-compose up --build -d
Creating network "test-module_internal" with the default driver
Creating network "test-module_default" with the default driver
Building greeter
Step 1/9 : FROM node:current-alpine
---> 0fcfd7e52b09
Step 2/9 : ENV NODE_ENV=production
---> Using cache
---> b7aa65f06df7
Step 3/9 : RUN mkdir /app
---> Using cache
---> 991f1d41b653
Step 4/9 : WORKDIR /app
---> Using cache
---> e819cda485cc
Step 5/9 : COPY package.json package-lock.json ./
---> Using cache
---> c98a973b66c4
Step 6/9 : RUN npm install --production
---> Using cache
---> 483de3cb4f9a
Step 7/9 : COPY . .
---> Using cache
---> 57df1e8c450c
Step 8/9 : EXPOSE 3000
---> Using cache
---> 67a7c553c734
Step 9/9 : CMD ["npm", "start"]
---> Using cache
---> ea1c648450cc
Successfully built ea1c648450cc
Successfully tagged test-module:latest
Building api
Step 1/9 : FROM node:current-alpine
---> 0fcfd7e52b09
Step 2/9 : ENV NODE_ENV=production
---> Using cache
---> b7aa65f06df7
Step 3/9 : RUN mkdir /app
---> Using cache
---> 991f1d41b653
Step 4/9 : WORKDIR /app
---> Using cache
---> e819cda485cc
Step 5/9 : COPY package.json package-lock.json ./
---> Using cache
---> c98a973b66c4
Step 6/9 : RUN npm install --production
---> Using cache
---> 483de3cb4f9a
Step 7/9 : COPY . .
---> Using cache
---> 57df1e8c450c
Step 8/9 : EXPOSE 3000
---> Using cache
---> 67a7c553c734
Step 9/9 : CMD ["npm", "start"]
---> Using cache
---> ea1c648450cc
Successfully built ea1c648450cc
Successfully tagged test-module:latest
Creating test-module_nats_1 ... done
Creating traefik ... done
Creating test-module-api ... done
Creating test-module-greeter ... done
✨ Done in 8.58s.
FYI, this is the source code which generated with the template
moleculer init jellydn/moleculer-template-project#patch-1 test-module
Used your template
moleculer init jellydn/moleculer-template-project#patch-1 test-module
Here is the result for npm run dc:up
On the other hand, this is what I get when I run npm run dc:up
after moleculer init project moleculer-demo
Ok, so could you show me what you have by the command docker ps
? Here is mine.
✝ ~/Projects/test-module docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
91a4ef50e2f5 test-module "docker-entrypoint.s…" 7 seconds ago Up 5 seconds 3000/tcp test-module-api
59c8d33adf5a test-module "docker-entrypoint.s…" 7 seconds ago Up 5 seconds 3000/tcp test-module-greeter
f0ecff8a6b9e traefik "/entrypoint.sh --ap…" 8 seconds ago Up 6 seconds 0.0.0.0:3000->80/tcp, 0.0.0.0:3001->8080/tcp traefik
5dc6258b81bc nats "/nats-server --conf…" 8 seconds ago Up 6 seconds 4222/tcp, 6222/tcp, 8222/tcp test-module_nats_1
Hey @jellydn
I'm on my Linux machine right now (my Win PC is at home). I've tried here but still couldn't call service actions.
Running npm run dc:up
it says that traefik
started successfully. However, docker ps
shows no reference of traefik
.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d67ee0067f99 test-module "docker-entrypoint.s…" 8 seconds ago Up 5 seconds 3000/tcp test-module-greeter
dcc7972e3e8c test-module "docker-entrypoint.s…" 8 seconds ago Up 4 seconds 3000/tcp test-module-api
1202a00e4fda nats "/gnatsd -c gnatsd.c…" 9 seconds ago Up 7 seconds 4222/tcp, 6222/tcp, 8222/tcp testmodule_nats_1
Don't know if it helps but I'm running:
Docker version 19.03.1, build 74b1e89
docker-compose version 1.24.1, build 4667896b
docker ps
on my Win machine
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c29b07797114 test-module "docker-entrypoint.s…" 7 seconds ago Up 5 seconds 3000/tcp test-module-api
d6aa50a1c972 test-module "docker-entrypoint.s…" 7 seconds ago Up 5 seconds 3000/tcp test-module-greeter
3ff487405ab8 nats "/gnatsd -c gnatsd.c…" 8 seconds ago Up 6 seconds 4222/tcp, 6222/tcp, 8222/tcp test-module_nats_1
@AndreMaz Thank you for your testing. Let me try to reproduce this issue.
Hello @AndreMaz I found this error when doing the yarn dc:up
on moleculer-demo folder (moleculer init project moleculer-demo
)
ERROR: for traefik Cannot create container for service traefik: Conflict. The container name "/traefik" is already in use by container "f0ecff8a6b9e0373a49cf9c3afc3376ad6d7c361021620a251958038789d33bf". You have to remove (or rename) that container to be able to reuse that name.
ERROR: Encountered errors while bringing up the project.
error Command failed with exit code 1.
then I got the same result with you docker ps
.
✘ ✝ ~/Projects/moleculer-demo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e5d19d52bcbe moleculer-demo "docker-entrypoint.s…" About a minute ago Up About a minute moleculer-demo-api
79e3f95dbb42 moleculer-demo "docker-entrypoint.s…" About a minute ago Up About a minute moleculer-demo-greeter
610abc0b75ba nats "/nats-server --conf…" About a minute ago Up About a minute 4222/tcp, 6222/tcp, 8222/tcp moleculer-demo_nats_1
Could you try remove all images then test again? Thank you in advance.
docker rmi $(docker images -a -q)
Hey @jellydn yeah removing all images solve the issue.
994392989d65 test-module "docker-entrypoint.s…" 5 seconds ago Up 3 seconds 3000/tcp test-module-api
e48b2893ceb1 test-module "docker-entrypoint.s…" 5 seconds ago Up 2 seconds 3000/tcp test-module-greeter
089212d46446 nats "/nats-server --conf…" 7 seconds ago Up 5 seconds 4222/tcp, 6222/tcp, 8222/tcp testmodule_nats_1
901b31216a17 traefik "/entrypoint.sh --ap…" 7 seconds ago Up 4 seconds 0.0.0.0:3000->80/tcp, 0.0.0.0:3001->8080/tcp traefik
The strange part in this situation is that I've never received any error. Running npm run dc:up
(prior to docker rmi $(docker images -a -q)
) was saying that 4 containers started successfully but in reality traefik
wasn't running.
The strange part in this situation is that I've never received any error
Hey @AndreMaz so I change the naming for traefik just in case someone ran into similar issue if they are testing 2 templates together. Please let me know if you have any idea. Thanks.
I think that there is no problem with the service/container name. It can stay as traefik. The problem is with image: traefik
It download the latest image. But if you have it locally (an older) docker won't download again, so it will use the old 1.7.
So use 2.x version tag in image name: traefik:2.0
After that if you have a local traefik with 1.7 version it will download the 2.0 and won't use the old one.
Or image name is traefik:latest
The traefik:latest
will cause the same problem when a v3.0 come out.
Of course, if you look at this decision as a long-term one, then will correctly commit the major version.
Thanks you all. I have changed to v2.0
.
I will close this PR until figure out the better solution, fyi.
I've played with it a little bit and I've found some settings what are unnecessary, I think. Here is my last state, maybe try to start from this:
version: "3.2"
services:
api:
build:
context: .
image: test-module
#container_name: test-module-api
env_file: docker-compose.env
environment:
SERVICES: api
PORT: 3000
labels:
- traefik.enable=true
- traefik.http.routers.web-api.rule=PathPrefix(`/`)
networks:
- internal
greeter:
build:
context: .
image: test-module
#container_name: test-module-greeter
env_file: docker-compose.env
environment:
SERVICES: greeter
networks:
- internal
traefik:
image: traefik:v2.0
#container_name: traefik
command:
# - --log.level=DEBUG
- --api.insecure=true
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --entrypoints.web.address=:3000
ports:
- 3000:3000
- 3001:8080
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
networks:
- internal
- default
networks:
internal:
It works from remote hosts as well because of - traefik.http.routers.web-api.rule=PathPrefix(
/)
It seems we can't skip the EXPOSE 3000
but in this case the PORT: 3000
under environment
is not relevant. So we should expose always the 3000 and traefik will manage what will be the endpoint port.
I suggest to wait a while
WHAT
Migrate from v1 to v2 https://docs.traefik.io/migration/v1-to-v2/
WHY
HOW
backend
,frontend
from v1