Ich bin neu bei Docker und versuche, eine Demo-Rails-App zu machen. Ich machte eine dockerfile die wie folgt aussieht:ERR_CONNECTION_REFUSED von Docker Container
FROM ruby:2.2
# Install apt based dependencies required to run Rails as
# well as RubyGems. As the Ruby image itself is based on a
# Debian image, we use apt-get to install those.
RUN apt-get update && apt-get install -y \
build-essential \
nodejs
# Configure the main working directory. This is the base
# directory used in any further RUN, COPY, and ENTRYPOINT
# commands.
RUN mkdir -p /app
WORKDIR /app
# Copy the Gemfile as well as the Gemfile.lock and install
# the RubyGems. This is a separate step so the dependencies
# will be cached unless changes to one of those two files
# are made.
COPY Gemfile Gemfile.lock ./
RUN gem install bundler && bundle install --jobs 20 --retry 5
# Copy the main application.
COPY . ./
# Expose port 3000 to the Docker host, so we can access it
# from the outside.
EXPOSE 3000
# The main command to run when the container starts. Also
# tell the Rails dev server to bind to all interfaces by
# default.
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]
ich es dann gebaut (keine Fehler):
docker build -t demo .
Und dann führen Sie es (auch keine Fehler):
docker run -itP demo
=> Booting Puma
=> Rails 5.1.1 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.8.2 (ruby 2.2.7-p470), codename: Sassy Salamander
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:9292
Use Ctrl-C to stop
Wenn Ich führe einen docker ps
Befehl in einem separaten Terminal, um die Ports zu bestimmen, bekomme ich:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
55e8224f7c15 demo "bundle exec rails..." About an hour ago Up About an hour 0.0.0.0:32772->3000/tcp ecstatic_bohr
Wenn ich jedoch versuchen, eine Verbindung entweder http://localhost:32772
oder http://192.168.99.100:32772
mit Chrome oder über einen Curl-Befehl herzustellen, erhalte ich eine "Verbindung verweigert".
Wenn ich die App außerhalb des Andockers auf meinem lokalen Computer über bundle exec rails server
Befehl ausführen, funktioniert es gut. Beachten Sie, dass ich Docker Toolbox auf meinem Win7-Rechner verwende
Was könnte ich falsch machen?
Sie setzen Port 3000 frei, aber Sie versuchen, 32772 zu erreichen? –
Ich exponiere 3000 innerhalb des Containers, der dann 32772 auf meinem localhost zugeordnet wird von dem, was ich sammle (mindestens per "0.0.0.0:32772-> 3000/tcp" über "docker ps" angezeigt) – Donald
Ich normalerweise verwenden docker-compose in Verbindung mit meiner dockerfile, um sicherzustellen, dass alles automatisch und konsistent eingerichtet wird. In Ihrer Dockerdatei würden Sie die Option "ports" verwenden und so etwas wie Ports machen: "8000: 8000" left 8000 ist docker Host, rechts 8000 ist docker container. – bkunzi01