DEV Community

Cover image for How to use Invoker with docker containers?
Insolita
Insolita

Posted on • Edited on

How to use Invoker with docker containers?

What is Invoker?
Invoker - is the universal data management tool for laravel/eloquent based applications You can see it features at https://invoker.dev/

It can work with local applications and with remote by ssh connection. But, unfortunately, it hasn't abilities for integration with apps that developed in dockers out of the box, because it distributed as executable gui application.
So we need to add an ssh service for our docker-compose.

  1. If you use separated containers for cli and fpm, you should use cli version as a base for a new ssh container. Otherwise, use your common php container.

  2. If you use prepared php image:

    • create new directory, named ssh in you folder with docker config
    • Inside this directory create new Dockerfile
FROM {your php image}

USER root
RUN apt-get update && apt-get install -y openssh-server \
    && mkdir /var/run/sshd \
    && echo 'root:secret' | chpasswd \
    && sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config \
    && sed -i 's/#PasswordAuthentication/PasswordAuthentication/' /etc/ssh/sshd_config \
    && sed -i 's/#PermitRootLogin/PermitRootLogin/' /etc/ssh/sshd_config \
    && sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd \
    && apt-get clean \
    &&  rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile

EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
Enter fullscreen mode Exit fullscreen mode

If you already use Dockerfile for php-cli service, copy it inside created ssh directory, remove CMD, ENTRYPOINT and EXPOSE instructions if it exists, and append ssh instructions above

add record in docker-compose.yml

services:
  sshd:
    build:
       context: your_docker_dir/ssh
    restart: on-failure
    ports:
    - '2266:22'
    links:
      - db # dabase service
      - php-cli  #php service
    volumes:
#for docker-compose < 3.x you can use volumes_from
      - data:/app  
    networks:
      - your_network  #if exists
Enter fullscreen mode Exit fullscreen mode

Run docker-compose up -d,
Open Invoker, press "Set up SSH connection", and fill

Alt Text

Next, you can explore your project models.

If you use docker-compose with version >= 3.4 - you can combine Dokerfile instructions like below

FROM php:7.4-cli as php_base #use preferred php image
# Place here your php installation and configuration instructions
FROM php_base AS php_ssh

USER root
RUN apt-get update && apt-get install -y openssh-server \
    && mkdir /var/run/sshd \
    && echo 'root:secret' | chpasswd \
    && sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config \
    && sed -i 's/#PasswordAuthentication/PasswordAuthentication/' /etc/ssh/sshd_config \
    && sed -i 's/#PermitRootLogin/PermitRootLogin/' /etc/ssh/sshd_config \
    && sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd \
    && apt-get clean \
    &&  rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile

EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
Enter fullscreen mode Exit fullscreen mode

And use it in docker-compose like:

services:
  php-cli:
    build:
      context: docker/php
      target: php_base
    restart: on-failure
    links:
      - db
      - redis
    volumes:
      - data:/app
    environment:
      - TZ=${DB_TIMEZONE}
      - PHP_XDEBUG_ENABLED=1
      - XDEBUG_CONFIG=remote_host=host.docker.internal
      - PHP_IDE_CONFIG="serverName=Docker"
    networks:
      - appnet
  sshd:
    build:
       context: docker/php
       target: php_ssh
    restart: on-failure
    ports:
    - '2266:22'
    links:
      - db
      - php-cli
    volumes:
      - data:/app
    networks:
      - appnet
Enter fullscreen mode Exit fullscreen mode

Don't forget to take care about keep ssh service only for the local environment!

Top comments (2)

Collapse
 
gander profile image
Gander • Edited

If you have a non-root user (e.g. dev) in the container and you want to log in to that user, replace this with a username. I did so to run it on my gander/dev image.

&& echo 'dev:secret' | chpasswd \
Enter fullscreen mode Exit fullscreen mode

Full working example for gander/dev.

Collapse
 
nexotaku profile image
Леонид Черненко

Thank you!

All worked as expected, I connected to Dockerized Laravel app :D

Great post!