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: 
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.
Copy the ip address in Docker subnet in Resources>Network in Docker Preferences in Mac:
[Docker preferences screenshot](https://i.stack.imgur.com/F1qcs.png)

As you can see from the screenshot link the ip address is

```
192.168.65.0

```

You just need to replace “localhost” in your containers config file with “192.168.65.1" (i.e. IP address picked + 1 ).

You can start your containers and should be set for local development/testing.

For some more details, you can see my article:
[Connect Docker containers the easy way](https://medium.com/@saif_nasir/connect-docker-containers-the-easy-way-60fae730fe0)