The frontend must docker skills (2) master

Outline

As a front-end, I feel the need to learn to use docker dry the following things:

  1. Deployment of front-end applications
  2. Nginx deployment
  3. To deploy nginx with https
  4. Use docker compose for deployment
  5. Nginx add to redis
  6. Use kubernetes

Here I follow the rhythm eleven research again, the experience recorded for later reference when developing, we believe it is useful to others.

References:

docker nginx
Beginner’s Guide

Nginx deployment

1. pull nginx mirror. Enter the following command remote pull the latest version of nginx mirror.

docker pull nginx:latest

2. Establish Dockerfile file in your home directory front-end project, write the following:

FROM nginx

3. Generate Mirror

docker build -t docker-nginx:latest .

4. Run image instance

docker run -d -p 2002:80 docker-nginx

5. Finally Open localhost: 2001 to see nginx standard welcome screen.

Do something

If we want to customize docker nginx configuration file inside it?

1. We enter docker-nginx container bash interface

docker exec -it [container_id] /bin/bash

2. Check the nginx configuration folder path

nginx -t

// 输出如下内容
// nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
// nginx: configuration file /etc/nginx/nginx.conf test is successful

You can see the configuration files in /etc/nginx/nginx.conf.

3. Check the contents of the configuration file

cat /etc/nginx/nginx.conf

// 在最下面可以看到这么一段
// include /etc/nginx/conf.d/*.conf;

In the bottom you can see such a period include /etc/nginx/conf.d/*.conf;, that is to say, vice configuration file in the /etc/nginx/conf.d/default.conf. We intend to rewrite the deputy profile.

4. rewritten Dockerfile file as follows:

FROM nginx
COPY default.conf /etc/nginx/conf.d/default.conf

In other words, replace docker inside default.conf with default.conf files in the current directory.

5. Finally image regenerate again and run to the container.

Note: The method I have here is not optimal , as well as mount configuration files, use docker compose method is much better than this, later introduced.

Guess you like

Origin www.cnblogs.com/yangzhou33/p/11539602.html