Docker container not connecting to any networks

I am trying to containerize a python script (I didn’t write the script and know very little python) so it can easily interact with one of my containers. I want this script to run on the same docker network as my other containers, which in this case is a user-defined bridge network called my_network. When using docker-compose, I am able to easily specify the network with Networks: - my_network. However, when I try to do that for this image, it does not seem to connect to my_network. I’ve also tried manually changing the network with docker network connect my_network container1 but docker inspect container still returns this:

"Networks": {
                "host": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "4cdc5abac597941053605ec4edd4ffff39038e154987d7aa6ad6265ea4d1cb3b",
                    "EndpointID": "",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "",
                    "DriverOpts": null
                }
            }

Why is this happening? Do I have to configure something in either the script or the Dockerfile in order to enable networking? I have never created or modified an image before, nor do I know very much python, so I will need a somewhat spoonfed answer if possible. Thanks!

Source: StackOverflow