docker build nginx + php + mysql + redis environment, it can be switched as required based version php

1, the directory structure

 

2, dockerfile file created to nginx Command set an example, to build from scratch the mirror] 

The FROM centos: Latest ------ centos based system images
 the MAINTAINER on Weeds <163 weedsyl @ .com> 
 ENV the TZ "Asia / of Shanghai" 
# installation depends 
the RUN yum -Y Update && \ --- the RUN command is an execution command of Dockerfile core part. It accepts a command as an argument and used to create a mirror  
    yum install -y gcc automake autoconf libtool make gcc-c ++ vixie-cron wget zlib file openssl-devel sharutils zip bash vim cyrus-sasl-devel libmemcached libmemcached-devel libyaml libyaml-devel unzip libvpx- devel openssl-devel ImageMagick-devel autoconf tar gcc libxml2-devel gd-devel libmcrypt-devel libmcrypt mcrypt mhash libmcrypt libmcrypt-devel libxml2 libxml2-devel bzip2 bzip2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype-devel bison libtool-ltdl-devel net-tools && \
  yum Clean All 
# install nginx 
RUN cd / tmp && \ 
    wget HTTP: //nginx.org/download/nginx-1.14.0.tar.gz && \ 
    tar xzf nginx-1.14.0 && .tar.gz \ 
    CD / tmp / nginx- 1.14.0 && \ 
    ./configure \ 
    --prefix = / usr / local / Nginx \ 
    --with-http_ssl_module --with-http_sub_module --with-http_dav_module --with -http_flv_module \
    --with-http_stub_status_module-http_gzip_static_module --with --with-Debug && \ 
    the make && \ 
    the make install 
EXPOSE 80 443     ---- open port 
# to start nginx 
CMD [ "/ usr / local / nginx / sbin / nginx", "-g", "daemon off; "] ---- and similar RUN command, CMD can be used to perform specific commands. And RUN difference is that these commands are not executed in the process of constructing the image, but rather is called after building a container with mirror

3, docker-compose.yml file to nginx for example [compose file is a definition of service, and network volumes YAML file. The default path Compose file is ./docker-compose.yml] 

Version: '2.1 ' - version 
services: --- Service 
  nginx: --- Name 
    Build: 
      context: ./nginx --- Dockerfile specified file path 
      dockerfile: dockerfile ---- dockerfile use this file to build the necessary build path specified 
    ports: - port mapping 
    - "$ {} NGINX_HOST_HTTP_PORT: 80" - read the file .env NGINX_HOST_HTTP_PORT value, the port 80 to the mapping docker .env host configuration port 
    - "$ {NGINX_HOST_HTTPS_PORT}: 443 " 
    volumes: --------- mount directory host directory: docker container directories 
    - ./nginx/logs:/usr/local/nginx/logs 
    - $ {} WORKPLACE: / usr / local / Nginx / HTML 
    - ./nginx/conf/nginx.conf:/usr/local/nginx/conf/nginx.conf:ro
    - ./nginx/conf/vhost:/usr/local/nginx/conf/vhost:ro 
    CONTAINER_NAME: nginx ------ container name 
    external_links: ----- link to an external container 
    - PHP 
    restart: Always - start with docker enabled NO 
  PHP: 
    Build: 
      context: ./php 
      dockerfile: dockerfile 
      args: 
        - WEEDS_PHP_VERSION} = $ {PHP_VERSION 
    the ports: 
    - "9000: 9000" 
    Volumes: 
    - $ {} WORKPLACE: / usr / local / Nginx / HTML 
    - ./php/conf/php${PHP_VERSION}.ini:/usr/local/php/lib/php.ini:ro 
    CONTAINER_NAME: PHP 
    external_links: 
    - MySQL 
    restart: Always

4, .env configuration

### NGINX #################################################
NGINX_HOST_HTTP_PORT=80 
NGINX_HOST_HTTPS_PORT=443

5, the startup directory

sudo docker-compose up -d nginx

6, after the success of

Docker PS Check the operation of the vessel 
Docker PS - A view of the container operation, including not running 
docker images listed local mirror 
Docker the kill "container id" kill container in a run or more, separated by a space 
Docker RM " container id "or how to remove a container 
dokcer rmi" id mirror "to remove the mirror, free up space 
Docker -compose restart / start / sTOP" container name "restart / start / stop

7. Other

GitHub Address: HTTPS: // github.com/weedsks/docker 
Docker's official website: HTTPS: // docs.docker.com/

 

Guess you like

Origin www.cnblogs.com/weedsyl/p/11646270.html