# Can't access ray server outside docker container

**URL:** <https://discuss.ray.io/t/cant-access-ray-server-outside-docker-container/15410>\
**Category:** Ray Serve\
**Created:** [July 31, 2024, 5:42pm UTC](https://discuss.ray.io/t/cant-access-ray-server-outside-docker-container/15410 "2024-07-31T17:42:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Renyu](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@Renyu](https://discuss.ray.io/u/Renyu)\
**Post date:** [July 31, 2024, 5:42pm UTC](https://discuss.ray.io/t/cant-access-ray-server-outside-docker-container/15410/1 "2024-07-31T17:42:51Z")

</div>

**How severe does this issue affect your experience of using Ray?**

- High: It blocks me to complete my task.

I am trying to set up run rayserve inside a docker container. The server is up and running inside the container but I can’t access the server at localhost:8000 **outside the docker container**. Based on my understanding, I need to specify a host of 0.0.0.0 when starting the ray server but I couldn’t find a way to do so despite spending hours trying suggested solutions from other threads. Could someone recommend the best way to achieve this with the latest ray image? Thank you!

Here is my docker-compose file:

```auto
services:
  ray-serve:
    container_name: ray-head
    build:
      context: ./
      dockerfile: Dockerfile
    ports:
      - 8265:8265
      - 8000:8000
    privileged: true

```

And here is my Dockerfile:

```auto
# Dockerfile
FROM rayproject/ray:nightly-aarch64

# Install any additional packages
RUN pip install ray ray[serve] requests

WORKDIR /app
COPY deployments /app/deployments

ENTRYPOINT ["ray", "start", "--head", "--port=6379", "--dashboard-host=0.0.0.0","--block"]

```

Here is my server code which is under `/deployments` directory.

```auto
#serve.py
from ray import serve

from starlette.requests import Request
from typing import Dict

@serve.deployment
class Hello:
    def __init__ (self):
        pass

    async def __call__ (self, starlette_request: Request) -> Dict:
        req = await starlette_request.json()
        name = req["name"]
        return {"response": f"Hello {name}!"}

serve.run(Hello.bind())

```

I tried several approaches but none of them work:

1. Using `serve run serve:app --host 0.0.0.0` from [this thread](https://discuss.ray.io/t/cannot-make-ray-server-ports-visible-in-docker/13447), I got an error: `Error: No such option: --host`
2. I also tried `serve.start(detached=True, http_options={"host": "0.0.0.0"}` from [this thread](https://discuss.ray.io/t/what-is-best-practice-for-local-setup/6507), but I couldn’t run `Hello.deploy()` in the end. I got an error saying Deployment object doesn’t have a method named deploy().
3. I also tried `serve deploy serve_config.yaml ` inside the container but I got an import error:

```auto
(base) ray@1ca327ef6946:/app/deployments$ serve status
applications:
  app1:
    status: DEPLOY_FAILED
    ...
      ModuleNotFoundError: No module named 'serve'

```

---

<div class="post-metadata">

**Author:** ![Renyu](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@Renyu](https://discuss.ray.io/u/Renyu)\
**Post date:** [July 31, 2024, 6:23pm UTC](https://discuss.ray.io/t/cant-access-ray-server-outside-docker-container/15410/2 "2024-07-31T18:23:20Z")

</div>

I figured it out after reading [this thread](https://discuss.ray.io/t/how-to-correctly-build-a-ray-serve-server-in-docker-with-a-generic-ubuntu-image-x86-64-in-an-amd-system/15336). Bascially I need to add the following lines to the serve.py:

```auto
import ray

ray.init()
serve.start(detached=True, http_options={"host": "0.0.0.0"})

```

Then in the docker container, simply run: `python serve.py` to start serving.

The full serve.py file is as follows for future reference:

```auto
from ray import serve
from starlette.requests import Request
from typing import Dict
import ray

ray.init()
serve.start(detached=True, http_options={"host": "0.0.0.0"})

@serve.deployment
class Hello:
    def __init__ (self):
        pass

    async def __call__ (self, starlette_request: Request) -> Dict:
        req = await starlette_request.json()
        name = req["name"]
        return {"response": f"Hello {name}!"}

serve.run(Hello.bind())

```
