Question: I have a code which has a button that gets the input of a text field and then afterwards looks through a .txt file, to see if there is a match. Only issue is it runs through each line and checks if that line matches, which means that both the *if* and *else* statement gets triggered. So lets say the .txt file has 3 lines saying *1234* , *5423* , *8543* and then the input would be *1234*, then the code runs as supposed for the if statement, as the input matches, which it is supposed to. But then it keeps going so it also triggers the else statement which it is not supposed to. 

This is my code
---------------

```
public static String input = "";

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        

        String input = jTextField1.getText();

        File file =new File("file.txt");
        Scanner in = null;
        try {
            in = new Scanner(file);
            while(in.hasNext())
            {
                String line=in.nextLine();
                if(line.contains(input)){

                    popUp1 pu1 = new popUp1();
                    pu1.setVisible(true);

                } else {

                    popUp2 pu2 = new popUp2();
                    pu2.setVisible(true);

                }
            }
        } catch (FileNotFoundException e) {
            System.out.println("Error");
        }

    }

```

Answer: 
The way to do this today is [Docker Networking](https://docs.docker.com/engine/userguide/networking/work-with-networks/).

The short version is that you can run `docker network ls` to get a listing of your networks. By default, you should have one called `bridge`. You can either create a new one or use this one by passing `--net=bridge` when creating your container. From there, containers launched with the same network can communicate with each other over exposed ports.

If you use [Docker Compose](https://docs.docker.com/compose/) as has been mentioned, it will create a bridge network for you when you run `docker-compose up` with a name matching the folder of your project and `_default` appended. Each image defined in the Compose file will get launched in this network automatically.

With all that said, I'm guessing your frontend is a webserver that just serves up the HTML/JS/CSS and those pages access the backend service. If that's accurate, you don't really need container-to-container communication in this case anyway... both need to be exposed to the host since connections originate from the client system.
There are multiple ways to do this and the simplest answer is to use
Docker-Compose. You can use Docker-compose to allow multiple services to run a server.

If you are not using Docker-Compose and running individual containers, then expose both services port with host and use those services on such on links like:

```
docker run -p 3306:3306 mysql
docker run -p 8088:80 nginx 

```

Now you can communicate as:

```
http://hostip:3306 
http://hostip:8088 

```

Now you can communicate with containers using hostIP.