Link 2 projects on your Desktop using the API
You might occasionally want to link two activeor projectsmore ondocker your Docker desktop.containers.
When your computer wants to connect to a website, it needs to talk to a DNS server to convert the URL to an IP Address same as the Docker desktop.
YouBasically, mustwhat convert the URLneeds to anbe IPdone Addressis to edit each of the competingdocker projectcontainer's /etc/hosts file and add in orderanother tocontainer's launchIP orand connect the two projects. Simply adhere to these few procedures to accomplish this:URL.
- The
twoprojects must be active on your Dockerdesktop.desktop and on the same network Go toEnter each project'sbashcontainerdocker exec -ti <container-name> bash
ToViewviewone container's /etc/hosts filecat /etc/hosts
- (the last entry on a newly built container should be the
IP addresses, open each host'container'sfileIP in the network)
- Add it in the other container's /
etcetc/hostsfolder.filecdecho.."<IP of the container from step 3> <URL of the container from step 3>" >> /etcetc/hosts
Using a script:
ConvertCopy theIPfollowingaddresscodeorand create ahostfileofputSourceIpIntoHosts.sh into therivaltargetprojectproject's root folder- Edit CONTAINER_SRC, CONTAINER_SRC_URL AND TARGET_CONTAINER
- Execute the script: ./putSourceIpIntoHosts.sh
Scenario:
In
this
Project 1: Recruitment Backend
Container name: recruitment-backendIP Address:
Project 2: Recruitment Frontend
NOTE: for our front-ends run: docker exec -ti recruitment sh
Container name: recruitment-frontend
Refer to the attached photos.
Step 1
Step 2
To save your modificationsis in vim:TARGET_CONTAINER
ESC
:wq
'{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $CONTAINER_SRC)If VIM is not found, install by running this commands:
Front-end / sh
Back-end/bash
1.
Credits: Sir Tyrel, Sir Jayditch, Ma'am Nicole
2.