mardi 18 avril 2017

Docker auto update host file for nginx webserver container

I'm trying to access my Docker container with an other url than localhost. The container is a nginx webserver serving static files of an Ember application. My nginxconfiguration looks like this :

server {
    listen       80;
    server_name  my-app.dev;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

And I would like to access my application through my-app.dev:8080. So my Dockerfile looks like this :

FROM nginx:alpine

COPY ./my-app-nginx.conf /etc/nginx/conf.d/default.conf

COPY ./dist /usr/share/nginx/html

EXPOSE 80

And my docker-compose.yml file like this :

version: "2"

services:
  web:
    restart: always
    image: me/my-app:latest
    build:
      context: .
      dockerfile: Dockerfile

    container_name: my-app

    # Keep the stdin open, so we can attach to our app container's process
    # and do things such as debugging, etc:
    stdin_open: true

    # Enable sending signals (CTRL+C, CTRL+P + CTRL+Q) into the container:
    tty: true

    ports:
      - "8080:80"

Everything almost work excpet that I have to modify my hostfile on my host machine to map 127.0.0.1 my-app.dev otherwise it doesn't work.




Aucun commentaire:

Enregistrer un commentaire