Sign inSign up

enomis/sidecar-custom

By enomis

•Updated over 4 years ago

Image
0

222

enomis/sidecar-custom repository overview

⁠DOCKER SIDECAR CUSTOM

Simple image used to perform automatic attach/detach of docker networks to specific containers.

The main use case is collaboration with the well-known docker image jwilder⁠, whose limitation is that it is always necessary to use the "Bridge" network or to know the defined networks in advance.

In the case of development environments managed by several developers, knowing the networks beforehand may not be feasible, whereas the use of "private" networks created for example with a docker-compose.yml file is now standard.

As a compromise, it is possible to use this "sidecar" image that will connect the container-proxy "jwilder-proxy" (the name does not have to be this) with the new networks at runtime, rather than removing the destroyed networks.

Another use case is when using images to be used as "bastions" or simply as "ssh tunnels" to containers in the environment: similarly to the above, it will also be possible to connect networks to these images at runtime, and run specific commands on them.

NOTE: this case is convenient if the image already has commands to perform the 'bulk' update action.

⁠USAGE

This image can update automagically because uses docker events system, which is ensured via docker socket.

So, to use this image you can run via docker run, but I prefer to use docker in combination to docker-compose, for example by using this docker-compose.yml file:

version: "3"
services:
  server:
    image: enomis/sidecar-custom
    volumes:
      - /<local.path>/docker.sock:/var/run/docker.sock
    environment:
      SIDECAR_NETWORK_TARGETS: "proxy-jwilder|cmd: nginx -s reload, other-images"

and execute via

docker-compose up -d server

where you can note:

  • mount of local /<local.path>/docker.sock to container path /var/run/docker.sock
  • SIDECAR_NETWORK_TARGETS, environment variable, in details:
    • it contains the list of images that that need to be updated via this image
    • the list is comma (,) separated
    • each part is composed of sections divided by pipe (|), in particular:
      • first part is always the specific container name
      • the cmd part is the command that should be runned into related container after network attach/detach **

** for example nginx -s reload to force re-update in jwilder/nginx-proxy container.

⁠IMAGE DETAILS

⁠Environments

Here the environment variables used from this image:

ENVIRONMENTDEFAULT VALUEDESCRIPTION
SIDECAR_NETWORK_TARGETS *-Configuration to specify target containers to which networks can be connected/removed
SIDECAR_DEBOUNCE_EXECUTION_TIMEemptyDebounce value in seconds, to avoid huge processing.
SIDECAR_DEFAULT_LOG_LEVELemptyPython Log library levels. See below.

* required

As you can see, the SIDECAR_NETWORK_TARGETS is mandatory and shoul be setted as explained in previous sections.

Log levels Table:

LEVELNumeric Value
CRITICAL50
ERROR40
WARNING30
INFO20
DEBUG10
NOTSET0

for more details see the official documentation⁠.

⁠DEBUG

For debugging you can use the follows yaml file:

version: "3"
services:
  sidecar:
    build:
      context: ./
    image: enomis/sidecar-custom
  server:
    image: enomis/sidecar-custom
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      SIDECAR_NETWORK_TARGETS: "jwilder-proxy|cmd: nginx -s reload, another-container-name"
  exec:
    image: enomis/sidecar-custom
    volumes:
      - ./:/usr/src/app
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      SIDECAR_NETWORK_TARGETS: "jwilder-proxy|cmd: nginx -s reload, another-container-name"
    command: "sh"
  test:
    image: enomis/sidecar-custom
    volumes:
      - ./:/usr/src/app
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      SIDECAR_NETWORK_TARGETS: "jwilder-proxy|cmd: nginx -s reload, another-container-name"
      SIDECAR_DEFAULT_LOG_LEVEL: 10
    command: "./test.py"

to run test.py, simply:

docker-compose run test

to access into image:

docker-compose run exec

Tag summary

Content type

Image

Digest

Size

23.5 MB

Last updated

over 4 years ago

docker pull enomis/sidecar-custom