Docker container configuration Nginx instance sharing _docker

Source: Internet
Author: User
Tags curl mkdir

As the current most popular application, Docker does exist in its unique, whether the program ape or Yun-dimensional should have heard of Docker's name, Docker has gone through a lot of pits, the latest version is the v1.11.0 version, it should be said to be fully capable of carrying the development and operation of monitoring, This tool helps us to efficiently package, publish, and run container systems that carry applications. And the collection of logs, to help the rapid development of the APP has a great effect.

Containers and virtual machines are often compared to two products, in fact, the two are fundamentally different, the virtual machine is a complete simulation of a real computer, the system running on it may or might not know that they are running in a virtualized environment, and the virtual machine hosts the conversion of user instructions to a privileged command of the function, So the virtual machine is very complex, but very complete, and Docker is completely different. Docker use the host's own Linux kernel, and then generate disk directories and software from the mirror, all processes running on the host, if interested can completely PS aux query, you can find in the Docker running process, but Docker do it as chroot The encapsulation of almost the concept.

Docker true Usage

In the early days of the Docker development, because of busybox and other lightweight mirrors are not complete, the major release of the reduction of thin mirror image has been more used, especially because Docker itself is developed in the Ubuntu environment, so Ubuntu and Debian in many mirrors as a base image, Use this as a basis for generating target mirroring. But with the use in practice, its drawbacks are also exposed, is too heavy, such as SYSTEMD log function and Docker itself log function is reused, the mirror is difficult to shrink to less than 300M. And the recommended use of Docker is a single process model, not multiple processes like a complete operating system. So produced a alpine, such as lightweight base mirror, Alpine is what can be its own Baidu, this mirror is Docker the official recommended mirror, the future of the official image will be migrated to Alpine as the basis of the mirror, so we should be familiar with this mirror as soon as possible.

Building Dockerfile

This article describes the Nginx practice of the Docker container, but the authorities actually have a alpine mirror image of Nginx. And in the actual use of the process, the author is more use Tengine, so according to the official Dockerfile reference, the author prepared the Tengine Mirror dockerfile, I hope to be able to comment, you can criticize.

From alpine:3.3 maintainer Chasontang <chasontang@gmail.com> env tengine_version 2.1.2 env CONFIG \--prefix= /etc/nginx \--sbin-path=/usr/sbin/nginx \--conf-path=/etc/nginx/nginx.conf \--error-log-path=/var/log/nginx /error.log \--http-log-path=/var/log/nginx/access.log \--pid-path=/var/run/nginx.pid \--lock-path=/var/run/ Nginx.lock \--http-client-body-temp-path=/var/cache/nginx/client_temp \--http-proxy-temp-path=/var/cache/nginx/p roxy_temp \--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \--http-uwsgi-temp-path=/var/cache/nginx/uwsgi _temp \--http-scgi-temp-path=/var/cache/nginx/scgi_temp \--user=nginx \--group=nginx \--with-http_ssl_ module \--with-http_realip_module \--with-http_addition_module \--with-http_sub_module \--with-http_da V_module \--with-http_flv_module \--with-http_mp4_module \--with-http_gunzip_module \--with-http_gzip_ Static_module \--wiTh-http_random_index_module \--with-http_secure_link_module \--with-http_auth_request_module \--with-mail \
    --with-mail_ssl_module \--with-file-aio \--with-http_spdy_module \--with-ipv6 \--with-jemalloc \  "ADD ngx_user.patch/add repositories/etc/apk/repositories RUN \ addgroup-s nginx \ && adduser-d-S
    -h/var/cache/nginx-s/sbin/nologin-g nginx nginx \ && apk add--no-cache--virtual. build-deps \ gcc \ 
  Libc-dev \ make \ openssl-dev \ pcre-dev \ zlib-dev \ linux-headers \ curl \ Jemalloc-dev \ && Curl "http://tengine.taobao.org/download/tengine-$TENGINE _version.tar.gz"-o tengine.tar.gz \ && m Kdir-p/usr/src \ && tar-zxc/usr/src-f tengine.tar.gz && rm tengine.tar.gz \ && cd/us r/src/tengine-$TENGINE _version/src/os/unix/\ && mv/ngx_user.patch/ngx_user.patch && Patch Ngx_us
  Er.c ngx_user.patch \&& RM ngx_user.patch \ && CD. /.. /..  /# && cd/usr/src/tengine-$TENGINE _version &&/configure $CONFIG--with-debug \ && make && mv Objs/nginx objs/nginx-debug &&/configure $CONFIG \ && make/&& make Install \ && rm-rf/etc/nginx/html/&& mkdir/etc/nginx/conf.d/&& mkdir-p/usr/share/  nginx/html/\ && install-m644 html/index.html/usr/share/nginx/html/&& install-m644 html/50x.html /usr/share/nginx/html/\ && install-m755 objs/nginx-debug/usr/sbin/nginx-debug && strip/usr/sbin /nginx* \ && rundeps= "$ (\ scanelf--needed--nobanner/usr/sbin/nginx \ | awk ' {gsub (/,/," \nso: ", $ 2); Print "So:" $} ' | Sort-u \ | Xargs-r apk info--installed \ | sort-u \) "\ && apk add--virtual. nginx-rundeps $runDeps \ && apk del build-deps \ && Rm-rf/usr/src/nginx-$NGINX _version \ && apk add--no-cache gettext \ # forward request and error logs to Docker log collector && Ln-sf/dev/stdout/var/log/nginx/access.log && ln-sf/dev/stderr/var/log/

Nginx/error.log copy nginx.conf/etc/nginx/nginx.conf copy nginx.vh.default.conf/etc/nginx/conf.d/default.conf

 Expose 443 CMD ["Nginx", "G", "daemon off;"]

We know that it Docker can be built on the Dockerfile Mirror, which is written by the author Dockerfile . First, use the from directive to specify that the base mirror for this mirror is alpine:3.3, the second behavior dockerfile the maintainer declaration, and then use two ENV directives to declare two environment variables, one to specify tengine need to obtain, and one to compile installation options. This is not explained here, then a patch file and Alpine mirrored source configuration file into the container, in fact, because Tengine v2.1.2 existence of a legacy glibc bug, can cause compile-time error, upstream Nginx the latest code has been fixed, and tengine open Hair Branch has also fixed this problem, the author has recently issue this patch to amend the Tengine v2.1.3 branch of the code, but unfortunately, v2.1.3 version has not yet been officially released, so you can only use patches to manually fix this problem. As for the mirror source, it is because there is a network problem in the country, which causes the APK package Management command to not successfully download the various dependencies, so it is designated as the domestic source, if the official use can remove the two files.

Then you use RUN the command to execute the code, here you can see the author using && and \ All the instructions are compressed to one line, here are two reasons:

The Run command does not save the working path of the previous instruction, and each run instruction only assigns the working directory AS/directory
An Dockerfile instruction in one will produce a mirrored submission, in other words, a reduced Dockerfile instruction can improve the reuse level of the mirror.
You then use the APK Package Management command to download the installation dependencies such as compilers, and to mark these dependencies as .build-deps groups for later uninstall and cleanup. Then is very conventional thinking,./ configure && make && make install , compile options are very standard, basic familiar with Nginx compiled friends can understand. But it can be noted that Nginx has been compiled two times, once the--with-debug parameters are turned on, not once, because in many cases, we need Nginx to provide debug-level monitoring logs, especially in the development environment, so we compile two times for ease of use. Then the string parsing process is used to extract the Run-time dependencies of the Tengine, marked as .nginx-rundeps then unloaded .build-deps , and finally two symbolic Links link Accesslog and ErrorLog to the standard input output, so that we can use the Docker logs command Easy to view the log. Finally, copy the custom Nginx configuration file and use Nginx-g daemon off; Let Nginx run the previous stage of the process.

Summarize

I've already finished here. Docker in the production and development of the correct use of the method, Docker is also really a good tool, I wish you early use of Docker to enhance their productivity.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.