Repository: abagayev/docker-bootstrap-collection Branch: master Commit: 1c6169699890 Files: 41 Total size: 16.1 KB Directory structure: gitextract_gmbhxb59/ ├── LICENSE ├── README.md ├── crontab-in-container/ │ ├── README.md │ ├── docker/ │ │ └── cron/ │ │ └── app │ └── docker-compose.yml ├── docker-registry/ │ ├── Readme.md │ ├── auth/ │ │ └── htpasswd │ └── docker-compose.yml ├── dynamodb-local/ │ ├── README.md │ └── docker-compose.yml ├── filebeat-logz-io/ │ ├── README.md │ ├── docker-compose.yaml │ ├── filebeat.yml │ └── logs/ │ └── example.log ├── lnmp-server/ │ ├── .gitignore │ ├── README.md │ ├── composer.json │ ├── docker-compose.yml │ └── public/ │ └── index.php ├── makefile-example/ │ ├── Makefile │ ├── README.md │ └── docker-compose.yml ├── multiple-services-with-common-network/ │ ├── Readme.md │ ├── master/ │ │ ├── docker-compose.yml │ │ └── public/ │ │ └── index.html │ └── slave/ │ └── docker-compose.yml ├── mysql-few-databases/ │ ├── README.md │ ├── docker/ │ │ └── provision/ │ │ └── mysql/ │ │ └── init/ │ │ └── 01-databases.sql │ └── docker-compose.yml ├── php-cli/ │ ├── Readme.md │ ├── app/ │ │ └── sum.php │ └── docker-compose.yml └── static-server/ ├── .babelrc ├── .gitignore ├── Dockerfile ├── Readme.md ├── docker-compose.yml ├── package.json ├── public/ │ └── index.html ├── src/ │ └── index.js └── webpack.config.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2018 Anton Bagaiev Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # Docker bootstrap collection Howdy! This is Docker bootstrap templates to start your new applications faster. ## Table of contents Basic web applications: * [Classic LNMP server](https://github.com/abagayev/docker-bootstrap-collection/tree/master/lnmp-server) * [Command line PHP](https://github.com/abagayev/docker-bootstrap-collection/tree/master/php-cli) * [Simple static server for JS apps](https://github.com/abagayev/docker-bootstrap-collection/tree/master/static-server) Basic databases and customization: * [MySQL with few databases](https://github.com/abagayev/docker-bootstrap-collection/tree/master/mysql-few-databases) * [DynamoDB for local development](https://github.com/abagayev/docker-bootstrap-collection/tree/master/dynamodb-local) Operations and service observability: * [Private Docker Registry](https://github.com/abagayev/docker-bootstrap-collection/tree/master/docker-registry) * [Filebeat configuration](https://github.com/abagayev/docker-bootstrap-collection/tree/master/filebeat-logz-io) * [Multiple docker compose services with common network](https://github.com/abagayev/docker-bootstrap-collection/tree/master/multiple-services-with-common-network) Tips and hacks: * [Crontab in container](https://github.com/abagayev/docker-bootstrap-collection/tree/master/crontab-in-container) * [Makefile example](https://github.com/abagayev/docker-bootstrap-collection/tree/master/makefile-example) ## Also Feel free to add comments, issues, pull requests or buy me a coffee: https://www.buymeacoffee.com/tonybug ================================================ FILE: crontab-in-container/README.md ================================================ # Crontab in docker compose example To enable crontab in your docker compose you need to use docker image with preinstalled cron and share crontab schedule in volumes. To try this example you need to up your compose and see date appending to the logs file every minute. ```shell docker-compose up -d cat logs/cron.log ``` Please don't forget to leave a blank line in the end of file. ================================================ FILE: crontab-in-container/docker/cron/app ================================================ # let's append current date to the log file every minute for a test * * * * * root /bin/echo Hello from `date` >> /tmp/logs/cron.log ================================================ FILE: crontab-in-container/docker-compose.yml ================================================ app: image: webdevops/php-nginx volumes: - ./docker/cron:/etc/cron.d - ./logs:/tmp/logs ================================================ FILE: docker-registry/Readme.md ================================================ # Private Docker Registry Run your registry with Docker compose, generate a login/password keys and login with new credentials: ```bash docker-compose up -d htpasswd -Bbn user pass > auth/htpasswd docker login https://0.0.0.0:443 ``` Then try to pull, tag and push an image to your new registry ```bash docker pull ubuntu docker tag ubuntu 0.0.0.0:5000/bubuntu docker push 0.0.0.0:443/bubuntu ``` If you are having trouble with message like `server gave HTTP response to HTTPS client`, just follow this link: https://stackoverflow.com/questions/38695515/can-not-pull-push-images-after-update-docker-to-1-12 ================================================ FILE: docker-registry/auth/htpasswd ================================================ user:$2y$05$cCibwxM8hHEijvPgmpk9he9nhxCiyPrw0CFLFVEwZUO.ImGuBM5hW ================================================ FILE: docker-registry/docker-compose.yml ================================================ registry: image: registry:2 ports: - 443:5000 environment: REGISTRY_AUTH: htpasswd REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm volumes: - ./registry:/var/lib/registry - ./auth:/auth ================================================ FILE: dynamodb-local/README.md ================================================ # DynamoDB for local development If you need DynamoDB at your project, just use this docker compose to add it to your environment. Also, this is configured to store data at volume, if you need it to store data in memory, just remove volumes and command directives. Also, this can be helpful for you: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html ================================================ FILE: dynamodb-local/docker-compose.yml ================================================ version: "3" services: dynamodb: image: amazon/dynamodb-local volumes: - dynamodb:/home/dynamodblocal command: [ "-jar", "DynamoDBLocal.jar", "-sharedDb", "-dbPath", "." ] volumes: dynamodb: driver: local ================================================ FILE: filebeat-logz-io/README.md ================================================ # Filebeat configuration This is an example of how to run Filebeat via Docker to send logs of your application to ELK stack at provider like [logz.io](https://logz.io). To make things work, do the next to prepare: 1. Create your configuration (or generate it with [configuration wizard](https://app.logz.io/#/dashboard/data-sources/Filebeat)) and store it to `filebeat.yml` 2. Add your logs directories to the list of volumes (or just try example logs prepared in _logs_ directiry) 3. Create certificates directory and download certificate ```shell mkdir -p cert && curl https://raw.githubusercontent.com/logzio/public-certificates/master/COMODORSADomainValidationSecureServerCA.crt > cert/COMODORSADomainValidationSecureServerCA.crt ``` Finally, run docker compose and check your ELK: ```shell docker-compose up -d ``` Can you see any logs? I hope you do. ================================================ FILE: filebeat-logz-io/docker-compose.yaml ================================================ version: "3" services: filebeat: image: docker.elastic.co/beats/filebeat:7.6.1 volumes: # filebeat configuration - "./filebeat.yml:/usr/share/filebeat/filebeat.yml:ro" # add your logs directories here - "./logs:/var/logs:ro" # install certificate - "./cert:/etc/pki/tls/certs:ro" # store filebeat data and don't lose it on container restart - "filebeat_data:/var/lib/filebeat:rw" volumes: filebeat_data: driver: local ================================================ FILE: filebeat-logz-io/filebeat.yml ================================================ ############################# Filebeat ##################################### filebeat.inputs: - type: log paths: - /var/logs/*.log fields: logzio_codec: plain token: %LOGZ_TOKEN% type: nginx fields_under_root: true encoding: utf-8 ignore_older: 3h #For version 7 and higher filebeat.registry.path: /var/lib/filebeat #The following processors are to ensure compatibility with version 7 processors: - rename: fields: - from: "agent" to: "beat_agent" ignore_missing: true - rename: fields: - from: "log.file.path" to: "source" ignore_missing: true ############################# Output ########################################## output: logstash: hosts: ["listener.logz.io:5015"] ssl: certificate_authorities: ['/etc/pki/tls/certs/COMODORSADomainValidationSecureServerCA.crt'] ================================================ FILE: filebeat-logz-io/logs/example.log ================================================ {"@timestamp":"2020–03–11T12:00:00.00+00:00","message":"This is a test message, can't you see it?", "level":"INFO"} {"@timestamp":"2020–03–11T13:00:00.00+00:00","message":"This is a test message number two, can't you see it too?", "level":"INFO"} {"@timestamp":"2020–03–11T14:00:00.00+00:00","message":"This is a test message number three, can't you see a tree?", "level":"WARNING"} ================================================ FILE: lnmp-server/.gitignore ================================================ /docker/volumes /vendor ================================================ FILE: lnmp-server/README.md ================================================ # Classic LNMP server This is an example of classic LNMP application(linux, nginx, mysql, php). Just add this docker-compose file to your application, change mysql credentials and you are ready to go. To build and test service use next command and check your application reaching [localhost](http://localhost): ```shell docker-compose up -d docker-compose exec app composer install ``` To connect with MySQL use next credentials(or change them in docker-compose): ``` MYSQL_HOST: db MYSQL_PORT: 3306 MYSQL_DATABASE: lnmp MYSQL_USER: root MYSQL_PASSWORD: local ``` If you want to connect to MySQL from outside(for example, with your IDE), use `localhost` for a host and port `3308` instead. ================================================ FILE: lnmp-server/composer.json ================================================ { "require": { }, "require-dev": { "fzaninotto/faker": "^1.7" } } ================================================ FILE: lnmp-server/docker-compose.yml ================================================ app: image: webdevops/php-nginx-dev:7.1 ports: - "80:80" volumes: - .:/app working_dir: /app environment: WEB_DOCUMENT_ROOT: /app/public PHP_DEBUGGER: xdebug PHP_IDE_CONFIG: serverName=lnmp-server XDEBUG_CONFIG: idekey=PHPSTORM XDEBUG_REMOTE_AUTOSTART: 1 XDEBUG_REMOTE_CONNECT_BACK: 0 XDEBUG_REMOTE_ENABLE: 1 XDEBUG_REMOTE_HOST: docker.for.mac.localhost # 172.17.0.1 for linux users XDEBUG_PROFILER_ENABLE: 0 links: - db db: image: mysql:latest command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci ports: - "3308:3306" volumes: - ./docker/volumes/db:/var/lib/mysql restart: always environment: MYSQL_DATABASE: lnmp MYSQL_USER: root MYSQL_PASSWORD: local MYSQL_ROOT_PASSWORD: local ================================================ FILE: lnmp-server/public/index.php ================================================ name; echo 'Hello, my name is ', $name, PHP_EOL; ================================================ FILE: makefile-example/Makefile ================================================ up: docker-compose up -d ps: docker-compose ps stop: docker-compose stop # combine two directives in one restart: stop up bash: docker-compose exec app bash ================================================ FILE: makefile-example/README.md ================================================ # Makefile example Makefile is a powerful tool to manage your containers and services easier. It is good to make shortcuts with commands like docker-compose and running container scripts like migrations, provision, configuration. For example, with Makefile in this folder, you can do the next: ```shell make up make ps make stop make restart make bash ``` Or even combine few directives from the command line, this will run your containers, show the list of them and get you inside of your app: ```shell make up ps bash ``` Please notice that make is not installed as default, try this for ubuntu: ```shell apt-get update && apt-get install build-essential ``` ================================================ FILE: makefile-example/docker-compose.yml ================================================ app: image: nginx ================================================ FILE: multiple-services-with-common-network/Readme.md ================================================ # Multiple docker compose services with common network Sometimes it is needed to share some resources between few docker compose services. For example, you are creating microservices with common database. To reach resource hosted on other service you need to create docker network and configure it as external network for both services. In this example we are creating common network, master service with nginx and slave service with curl, witch can call nginx resource as well. ```bash # create and check network docker network create services-common-network docker network ls | grep services-common-network # create master service docker-compose -f master/docker-compose.yml up -d # create slave service and test master nginx from slave docker-compose -f slave/docker-compose.yml up -d docker-compose -f slave/docker-compose.yml run alpine-curl nginx ``` To remove network you need to stop your services first (you can't remove network with active endpoints). ```bash docker-compose -f master/docker-compose.yml stop docker-compose -f slave/docker-compose.yml stop docker network rm services-common-network ``` ================================================ FILE: multiple-services-with-common-network/master/docker-compose.yml ================================================ version: '3' networks: services-common-network: external: true services: nginx: image: nginx volumes: - ./public:/usr/share/nginx/html networks: - services-common-network ================================================ FILE: multiple-services-with-common-network/master/public/index.html ================================================
Last time you was here ...
================================================ FILE: static-server/src/index.js ================================================ import cookies from "browser-cookies"; global.myApp = { // get last visit date from cookies getLastVisit: () => { const last_visit = cookies.get("last_visit"); return last_visit; }, // set last visit value setLastVisit: (value) => { cookies.set("last_visit", value || (new Date()).toISOString(), { expires: 365 }); } }; ================================================ FILE: static-server/webpack.config.js ================================================ var webpack = require('webpack'); module.exports = { output: { path: __dirname + "/public/dist", filename: "main.js" }, module: { rules: [ { test: /\.js$/, exclude: /node_modules/, use: { loader: "babel-loader" } } ] }, plugins: [ new webpack.DefinePlugin({ 'SDK_BUILD_ID': JSON.stringify(process.env.BUILD_ID), }) ] };