0

I am learning Docker and trying to run container on Win11, which is running successfully, but it doesn't connect to localhost.

This is my Dockerfile

FROM ruby:3.1.2

RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
WORKDIR /test
COPY Gemfile /test/Gemfile
COPY Gemfile.lock /test/Gemfile.lock
RUN bundle install
EXPOSE 3000

COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000

CMD ["rails", "server", "-b", "0.0.0.0"]

And docker-compose.yml

services:
  db:
    image: postgres:14.8
    volumes:
      - ./tmp/db:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: 12345
  web:
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
      - .:/test
    ports:
      - "3000:3000"
    depends_on:
      - db

After I run docker compose up console shows that Server is running.

console logs

But when I open the localhost there is an error.

error message - Unable to connect

dfx
  • 3
  • 4
  • Does this answer your question: https://stackoverflow.com/questions/40746453/how-to-connect-to-docker-host-from-container-on-windows-10-docker-for-windows – engineersmnky Jul 26 '23 at 21:01
  • Please include errors as text, not screenshots. – doneforaiur Jul 27 '23 at 05:04
  • Why dnt you use `127.0.0.1` ? 127.0.0.1 is the localhost. 0.0.0.0 is localhost also, but rails uses extra step for it. Nor you can touch the `/etc/hosts` and mention the localhost on any IP. – 7urkm3n Jul 28 '23 at 02:06

0 Answers0