Skip to content

docker / serve / WebSocket connection to 'ws://0.0.0.0:3000/__livereload' failed: bad URL #1698

@aheissenberger

Description

@aheissenberger

problem:
The web socket connection fails if the IP of the website is not equal to the IP used to start mdbook serve which is different when started in a docker container.

setup:

  • docker compose with the ports 0.0.0.0:3000 (docker container) => 127.0.0.1:3000 (host) and 3001:3001 mapped.
  • page is visible but refresh fails after change

The problem is, that mdbook server has to listen on all external ports in the container:
mdbook server --hostname '0.0.0.0'

The page preview is viewed under http://127.0.0.1:3000

Dockerfile

FROM rust as builder

RUN cargo install mdbook ; \
    cargo install mdbook-toc; \
    cargo install mdbook-mermaid;

FROM debian:buster-slim
RUN apt-get update && rm -rf /var/lib/apt/lists/*
COPY --from=builder \
    /usr/local/cargo/bin/mdbook \
    /usr/local/bin/
COPY --from=builder \
    /usr/local/cargo/bin/mdbook-toc \
    /usr/local/bin/
COPY --from=builder \
    /usr/local/cargo/bin/mdbook-mermaid \
    /usr/local/bin/

WORKDIR /mdbook

docker-compose.yml

version: "3"
services:
  mdbook:
    build: ./.docker
    volumes:
      - "${PWD}:/mdbook"
    stdin_open: true
    tty: true
    ports:
      - "3000:3000"
      - "3001:3001"
    entrypoint: "/usr/local/bin/mdbook"
    command:
      - serve
      - --hostname
      - '0.0.0.0'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions