Conexión rechazada en el contenedor docker


Soy nuevo en Docker e intento hacer una aplicación Rails de demostración. Hice un dockerfile que se ve así:

FROM ruby:2.2
MAINTAINER [email protected]

# 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 8080 to the Docker host, so we can access it 
# from the outside.
EXPOSE 8080

# 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", "-p", "8080"]

Entonces lo construí así:

docker build -t demo . 

Y llama a un comando para iniciar el servidor que inicia el servidor en el puerto 8080:

Johns-MacBook-Pro:demo johnkealy$ docker run -it demo
=> Booting WEBrick
=> Rails 4.2.5 application starting in development on http://0.0.0.0:8080
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2016-04-23 16:50:34] INFO  WEBrick 1.3.1
[2016-04-23 16:50:34] INFO  ruby 2.2.4 (2015-12-16) [x86_64-linux]
[2016-04-23 16:50:34] INFO  WEBrick::HTTPServer#start: pid=1 port=8080

Luego trato de encontrar la IP correcta para navegar a:

Johns-MacBook-Pro:demo johnkealy$ docker-machine ip default
192.168.99.100

Navego a http://192.168.99.100:8080 y obtener el error Este sitio no se puede alcanzar 192.168.99.100 se negó a conectarse.

¿Qué podría ser haciendo mal ?

 30
Author: jdkealy, 2016-04-23

2 answers

Debe publicar los puertos expuestos utilizando las siguientes opciones:

-P (mayúsculas) o publish publish-all que le dirá a Docker que use puertos aleatorios de su host y los mapeará a los puertos del contenedor expuesto.

-p (minúscula) o publish publish=[] que le indicará a Docker que use los puertos que establezca manualmente y los mapeará a los puertos del contenedor expuesto.

Se prefiere la segunda opción porque ya sabe qué puertos están mapeados. Si utiliza el primer opción entonces tendrá que llamar a docker inspect demo y comprobar qué puertos aleatorios se están utilizando desde su host en la sección Ports.

Simplemente ejecute el siguiente comando:

docker run -it -p 8080:8080 demo

Después de eso, tu url funcionará.

 28
Author: CodeNotFound,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-16 19:42:33

Si está utilizando Docker toolkit en window 10 home necesitará acceder a la página web a través del comando docker-machine ip. Es generalmente 192.168.99.100:

Se asume que se está ejecutando con el comando publish como se muestra a continuación.

docker run -it -p 8080:8080 demo

Con la versión Windows 10 pro puede acceder con localhost o loopback correspondiente 127.0.0.1:8080, etc. (Tomcat o lo que desee). Esto se debe a que no tiene una caja virtual allí y docker se está ejecutando directamente en Ventana Hyper V y loopback es directamente accesible.

Verifique el archivo hosts en la ventana para cualquier digresión. Debería haber 127.0.0.1 mapeado a localhost

 16
Author: vimal krishna,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-20 13:14:03