Image docker running through port 80

2

A couple of days ago that I'm fiddling with Docker, I tell you my intention.

Create a Dockerfile with:

  • LAMP
  • Wordpress
  • Nodejs
  • npm
  • ionic-framework
  • cordova

And that from port 80 using "localhost" can access the wordpress.

I have mounted a Dockerfile in which everything works correctly except when I start the image, if I start it to access from the console:

sudo docker run -i -t nombre_imagen /bin/bash Everything works OK!

But if I try to boot it against port 80

sudo docker run -d -p 80:80 nombre_imagen Does not start: '(

I pass the content of the Dockerfile.

# This is my first Dockerfile

FROM ubuntu:14.04
MAINTAINER Marc Torres <[email protected]>


# Instalamos dependencias
    # apache2: Servidor Web
    # php5: Lenguaje de programacion PHP
    # php5-mysql: Driver de MySql para PHP
    # supervisor: Lanzadaror y Monitor de procesos
    # wget: Utilidad para obtener archivos via HTTP
    # unzip: Para descromprimir
    # nodejs
    # npm
  RUN apt-get update && apt-get -y install \
    apache2 \
    php5 \
    php5-mysql \
  #  supervisor \
    wget \
    unzip \
    nodejs \
    npm

# fucking debian installs 'node' as 'nodejs'
  #RUN update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10

  # mysql-server se instala con intervención del usuario,
  # pero como no es modo interactivo lo que hacemos es setearle las variables
  # con un valor.
  # Para simplificar hemos usado como usuario y contraseña de mysql 'root'
  RUN echo 'mysql-server mysql-server/root_password password root' | \
    debconf-set-selections && \
    echo 'mysql-server mysql-server/root_password_again password root' | \
    debconf-set-selections

  # Procedemos ahora sí, a instalar mysql-server
  RUN apt-get install -qqy mysql-server

  # Preparamos Wordpress
    # Obtenemos la última versión
    # Descomprimimos
    # Copiamos el contenido dentro del root del servidor
    # Removemos el viejo index.html (mensaje de bienvenida de apache)
  RUN wget http://wordpress.org/latest.tar.gz && \
    tar xzvf latest.tar.gz && \
    cp -R ./wordpress/* /var/www/html && \
    rm /var/www/html/index.html \
    rm -rf /latest.tar.gz

  # descargamos plug-in WP-REST API y lo metemos en la carpeta plugins
  RUN wget https://downloads.wordpress.org/plugin/json-rest-api.1.2.5.zip
  RUN unzip json-rest-api.1.2.5.zip -d /var/www/html/wp-content/plugins/
  RUN rm -rf /json-rest-api.1.2.5.zip

  # ejecutamos a mysql en background y creamos la base de datos llamada wordpress
  RUN (/usr/bin/mysqld_safe &); sleep 5; mysqladmin -u root -proot create wordpress

  # Reemplazamos el archivo wp-config.php (más abajo lo creamos) a la carpeta de wordpress
  # Este archivo contiene la configuración de nuestro sitio
  COPY wp-config.php /var/www/html/wp-config.php

  # instalamos git
  RUN apt-get -y install git

  # instalamos ionic en entorno global -g
  RUN npm install -g ionic-framework

  # instalamos cordova de forma global -g
  RUN npm install -g cordova

  #creamos link para evitar errores de node
  RUN ln -s /usr/bin/nodejs /usr/bin/node

  # Le decimos al contenedor que tiene que hacer accesible al puerto 80 (en el que corre HTTPD)
  # para así nosotros poder acceder al mismo desde fuera
  EXPOSE 80

Thank you!

    
asked by Marc Torres 08.11.2016 в 16:27
source

3 answers

1

Try adding tail -f / dev / null to your command in the following way.

sudo docker run -d -p 80:80 nombre_imagen tail -f /dev/null

This occurs when no process of your docker runs in foreground. Check out this Stack Overflow English answer link

    
answered by 08.11.2016 / 18:03
source
0

The correct thing is that you separate everything in different containers, as a recommendation uses the official docker images: wordpress, php, node.

Your problem that does not start is because you are not running one container per service. The advisable thing is that you only run one service per container and the links with each other with docker-compose.

The recommendable thing is that the stack you create with docker-compose

    
answered by 11.07.2017 в 18:54
0

In the DOCKERFILE you must declare which port you use with EXPOSE 80 and then when doing docker run you have to use the -p parameter:

docker run -d -p 80:80

    
answered by 08.11.2017 в 14:05