When I was playing with Docker, I couldn't distinguish the relationship between the host port and the container port, so the connection failed. In the end, it took a lot of time to learn to understand, so I wrote this article to record my growth
Connection key:
Containers connected to each other need to be on the same network. As docker-compose.ymlset the same networksvalue
Access between containers, using the container's own port
Personal experience:
The host machine is laradockinstalled gitlabwith the jenkinscontainer. Host through http://localhost:8989normal access gitlabthe webpage by http://localhost:8090normal access jenkinsof webpage
I would like jenkinsthere to access gitlabthe page, and then http://localhost:8989the localhostswitch to 127.0.0.1, container IP, container name, but all connections are failed
Then after NN hours of reviewing information and testing, it was finally found that the mutual access between containers was based on the same network and then accessed through the open ports of the container itself, which had nothing to do with mapping.
Thus, in docker-compose.ymlsettings in the profile gitlabof jenkinsthe container networksis the same value, are set tobackend
networks:
- backend
Finally jenkinspass inside http://gitlabto access. URLThe ones in gitlabwill be parsed into gitlabcontainers IP. The 8989port is not used here because gitlabthe webpage is on the 80port of the container