Docker realizes the interconnection of containers

Docker realizes the interconnection of containers

writing background:

  1. 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:

  1. Containers connected to each other need to be on the same network. As docker-compose.ymlset the same networksvalue
  2. Access between containers, using the container's own port

Personal experience:

  1. The host machine is laradockinstalled gitlabwith the jenkinscontainer. Host through http://localhost:8989normal access gitlabthe webpage by http://localhost:8090normal access jenkinsof webpage
  2. 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
  3. 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.
  4. Thus, in docker-compose.ymlsettings in the profile gitlabof jenkinsthe container networksis the same value, are set tobackend
  networks:
    - backend
  1. 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

Guess you like

Origin blog.csdn.net/DBCai/article/details/115273778