Currently Browsing: Misc Tech

Consumer-Driven Contracts: links

I like the idea of CDC, certainly easier to aspire to than to implement, would be interested to hear actual success stories.

Also the examples showing 1-to-1 matching criteria seem to against the intention of “not caring exactly what the data is, as long as it satifies my needs”.

Consumer-Driven Contracts: A Service Evolution Pattern

https://martinfowler.com/articles/consumerDrivenContracts.html

https://docs.pact.io/

https://github.com/pact-foundation/pact-js

https://docs.pact.io/documentation/matching.html

Also seems like a server-side validator like Joi could be pretty useful for this purpose:

http://vawks.com/blog/2014/03/22/the-joi-of-validation/

Docker Compose LAMP demo project

Project showing a basic LAMP set-up using a networked multi-container configuration.

docker-compose.yml

version: '2'
services:
  php:
     image: phpmyadmin/phpmyadmin
     links:
       - mysql:db
     depends_on:
       - mysql

  mysql:
    image: k0st/alpine-mariadb
    volumes:
      - ./data/mysql:/var/lib/mysql
    environment:
      - MYSQL_DATABASE=mydb
      - MYSQL_USER=myuser
      - MYSQL_PASSWORD=mypass 

  nginx:
    image: nginx:stable-alpine
    ports:
      - "81:80"
    volumes:
      - ./nginx/log:/var/log/nginx
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./nginx/files:/var/www/nginx:ro
    depends_on:
      - php

nginx/nginx.conf

worker_processes  1;
events {
  worker_connections  1024;
}
http {
  sendfile  off;
  server {
    listen 80;
 
    location / {
      proxy_pass  http://php;
      proxy_set_header Host $host;
      proxy_redirect     off;
    }
  }
}

The nginx config is simplified but that should work for testing — basically all it’s doing is proxying the php app. Maps to port 81 to avoid conflicts on the host. (Note this is just a rough demo, would need to be fleshed out for any use more than that.)

Regarding linking, you can see that if you run: docker-compose exec mysql ping -c2 nginx to ping from the mysql container to the nginx container, you will succeed even though there are no links specified between these containers. Docker Compose will maintain those links in the default network for you.

If you like, you can fetch a working version from this repo and run docker-compose up, and (assuming you don’t have anything running on port 81) see results on http://localhost:81/ (or whatever your corresponding hostname/IP is).

For more info on Docker Compose networking see: https://docs.docker.com/compose/networking/

By default Compose sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.

Links allow you to define extra aliases by which a service is reachable from another service. They are not required to enable services to communicate Рby default, any service can reach any other service at that service’s name.

Docker remove only exited containers

To remove just the containers that have exited as opposed to all (ps -aq) you can do:

docker rm $(docker ps -a | grep Exit | cut -d ' ' -f 1)

Connect to Docker for Mac Alpine Host

The new Docker for Mac (mid-2016) doesn’t work the same way as previous versions or the native linux version. To interact with the Docker Host VM, instead of SSH, you can use:

screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty

and login with root user. No password should be required.

You can also get networking, etc info about the host by querying a container host-networked like so:

docker run --rm --privileged --net=host alpine ifconfig

Docker stop and remove all active containers

docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q)

« Previous Entries