You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
2. Create a `Dockerfile` file in the root of your project.
331
+
332
+
```Dockerfile
333
+
FROM node:10
334
+
COPY ./ /app
335
+
WORKDIR /app
336
+
RUN npm install && npm run build
337
+
338
+
FROM nginx
339
+
RUN mkdir /app
340
+
COPY --from=0 /app/dist /app
341
+
COPY nginx.conf /etc/nginx/nginx.conf
342
+
```
343
+
344
+
3. Create a `.dockerignore` file in the root of your project
345
+
346
+
Setting up the `.dockerignore` file prevents `node_modules` and any intermediate build artifacts from being copied to the image which can cause issues during building.
347
+
348
+
```gitignore
349
+
**/node_modules
350
+
**/dist
351
+
```
352
+
353
+
4. Create a `nginx.conf` file in the root of your project
354
+
355
+
`Nginx` is an HTTP(s) server that will run in your docker container. It uses a configuration file to determine how to serve content/which ports to listen on/etc. See the [nginx configuration documentation](https://www.nginx.com/resources/wiki/start/topics/examples/full/) for an example of all of the possible configuration options.
356
+
357
+
The following is a simple `nginx` configuration that serves your vue project on port `80`. The root `index.html` is served for `page not found` / `404` errors which allows us to use `pushState()` based routing.
358
+
359
+
```text
360
+
user nginx;
361
+
worker_processes 1;
362
+
error_log /var/log/nginx/error.log warn;
363
+
pid /var/run/nginx.pid;
364
+
events {
365
+
worker_connections 1024;
366
+
}
367
+
http {
368
+
include /etc/nginx/mime.types;
369
+
default_type application/octet-stream;
370
+
log_format main '$remote_addr - $remote_user [$time_local] "$request"'
371
+
'$status $body_bytes_sent "$http_referer"'
372
+
'"$http_user_agent""$http_x_forwarded_for"';
373
+
access_log /var/log/nginx/access.log main;
374
+
sendfile on;
375
+
keepalive_timeout 65;
376
+
server {
377
+
listen 80;
378
+
server_name localhost;
379
+
location / {
380
+
root /app;
381
+
index index.html;
382
+
try_files $uri $uri/ /index.html;
383
+
}
384
+
error_page 500 502 503 504 /50x.html;
385
+
location = /50x.html {
386
+
root /usr/share/nginx/html;
387
+
}
388
+
}
389
+
}
390
+
```
391
+
392
+
5. Build your docker image
393
+
394
+
```bash
395
+
docker build . -t my-app
396
+
# Sending build context to Docker daemon 884.7kB
397
+
# ...
398
+
# Successfully built 4b00e5ee82ae
399
+
# Successfully tagged my-app:latest
400
+
```
401
+
402
+
6. Run your docker image
403
+
404
+
This build is based on the official `nginx` image so log redirection has already been set up and self daemonizing has been turned off. Some other default settings have been setup to improve running nginx in a docker container. See the [nginx docker repo](https://hub.docker.com/_/nginx) for more info.
0 commit comments