Skip to content

Instantly share code, notes, and snippets.

@navix
Created February 11, 2019 11:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save navix/e454ea4a4cd7c32fa9705cd76b639f77 to your computer and use it in GitHub Desktop.
Save navix/e454ea4a4cd7c32fa9705cd76b639f77 to your computer and use it in GitHub Desktop.
Docker image with Angular application

Docker image with Angular application

How to build a Docker image that serves Angular application (without Universal).

Build your application to the dist/app directory, then copy it into an image.

Dockerfile

FROM nginx:latest

COPY ./etc/nginx.conf /etc/nginx/nginx.conf

ADD ./dist/app /var/app/

nginx.conf

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
  worker_connections 768;
  # multi_accept on;
}

http {
  # Basic Settings
  sendfile off;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  types_hash_max_size 2048;
  # server_tokens off;
  # server_names_hash_bucket_size 64;
  # server_name_in_redirect off;
  include /etc/nginx/mime.types;
  default_type application/octet-stream;

  # Logging Settings
  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;

  server {
    listen 80 default_server;
    charset utf-8;
    set $root_path '/var/app';
    root $root_path;
    location ~* ^.*$ {
      root $root_path;
      try_files $uri $1/index.html =404;
    }
  }
}

Build image:

$ docker build -t IMAGE_NAME .

After that you can use the image and load your application from the 80 port.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment