Closed carlospliego closed 6 years ago
I recommend to not use the (legacy) container links but to use a custom network instead. In fact running your backend on a different network than the default network seems to be the cause that your container link does not work.
If you want to have your angular container conntected to multiple networks, you need to separate the container creation and startup phases. So you would use separate docker create
and docker start
commands.
If you automate this process keep in mind that your backend might take longer to startup than the frontend, so you need to either implement some way to wait for the backend or use a heuristic sleep().
It might be more convenient to use docker-compose to orchestrate multiple containers.
Let me know if this solves your issue.
So I am using compose and linking via the link option.
server:
ports
- 3000:5000
links:
-mongodb
ng:
ports:
- 3001:4200
links:
- server
when starting docker run -u $(id -u) --rm -v "$PWD":/app trion/ng-cli-e2e ng e2e
I tried using the --net
option while looking up the running network on the server.
The problem is that my angular application is making requests to port 3000. compose links work fine, but I can't figure out how to link your running container to my server.
df60a0a6bea9 bridge bridge local
d401410d48f5 host host local
5e31c567785e root_default bridge local
2d406ad8f8fa ng_default bridge local
72c3fa5648ea server_default bridge local
Please use custom networks as links are deprecated. See the warning at https://docs.docker.com/compose/compose-file/#links You need to use http://server:3000/ as target for requests from the frontend inside the e2e container. (When using custom networks DNS entries for the services will be created as with the links)
All resolved! Thank you, great advise on the networking with compose.
Running
docker run -u $(id -u) --rm -v "$PWD":/app trion/ng-cli-e2e ng e2e
works as expected. This container seems to run the angular application on port49152
I have a backend container running on the network on port
3000
Any idea how I can make sure the database is connected. perhaps via link?Getting this error
docker: Error response from daemon: Cannot link to /kilterly_server_1, as it does not belong to the default network.
when trying to run :docker run --link $(SERVER_CONTAINER) -....