0

My API couldn't be published on the specific ip address (VM host) when using docker

First, I run the file in terminal : Rscript run.R

This works fine, my api is up and running on the ip address http://35.157.131.3:8000/swagger/ . After which, I would like to deploy it with docker:

docker run --rm -p 8000:8000 --expose 8000 -d --name diemdiem trestletech/plumber

This showed the file was plumbed successfully, however, when i went to the api link, http://35.157.131.3:8000/swagger/ showed 404-error.

After reading docker documentations, i created a container network which specifies the host ip address that i want the docker container would run on:

-o "com.docker.network.bridge.host_binding_ipv4"="35.157.131.3" \
simple-network````

then, i connect the running diemdiem container to simple-network:

``` docker network connect simple-network diemdiem```
I inspect to see whether the container is connected or not:
```docker network inspect simple-network```
The result is: 

[
    {
        "Name": "simple-network",
        "Id": "95ec0c55aeb984952459edda2d4d0bb7c9eea71824e6cec184b7c61d2e807e7b",
        "Created": "2019-07-08T17:30:23.709654207Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.21.0.0/16",
                    "Gateway": "172.21.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "c83125bf68a89aebda3effe28ebee4d6323657e1427cf08fd3d63b6e411f8448": {
                "Name": "diemdiem",
                "EndpointID": "7fab3354e051dc81ef798bd86c19361f6a721b578237b3a3695cb415b1aee2e4",
                "MacAddress": "02:42:ac:15:00:02",
                "IPv4Address": "172.21.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.bridge.host_binding_ipv4": "35.157.131.3"
        },
        "Labels": {}
    }
]

The final API is still not up and running in the ip address which i specified. I appreciate your advice.
  • If you're getting an HTTP 404 error, your browser or other HTTP client is successfully connecting to _something_; the Docker networking settings you're trying to change probably aren't the problem. The `-p` option you show in your original command should be all you need (you do not need `--expose` even). – David Maze Jul 08 '19 at 18:34
  • yep, it connects to something but if it works successfully, the URL http://35.157.131.3:8000/swagger/ should be up and running like when i deployed in the terminal without docker :( – Diem Nguyen Jul 08 '19 at 18:46

0 Answers0