Using docker-compose (formerly fig) to link a cron image

I’m runing a simple rails app in docker using docker-compose (formerly fig) like this:

docker-compose.yml

  • understanding what Docker stdin and stdout mean
  • why won't my fluentd work with elasticsearch
  • Kuberenets Web UI (Dashboard) missing graphs
  • Docker environment variables in php
  • How can I use nginx to forward incoming requests from a certain URL on port 80 to various docker applications
  • How to hot deploy Java EE applications in Docker containers
  • db:
      image: postgres
      volumes:
        - pgdata:/var/lib/postgresql/data
    
    web:
      build: .
      command: bundle exec rails s -b 0.0.0.0
      volumes:
        - .:/usr/src/app
      ports:
        - "3011:3000"
      links:
        - db
    

    Dockerfile

    FROM rails:onbuild
    

    I need to run some periodical maintainance scripts, such as database backups, pinging sitemaps to search engines etc.

    I’d prefer not to use cron on my host machine, since I prefer to keep the application portable and my idea is to use docker-compose to link an image such as https://registry.hub.docker.com/u/hamiltont/docker-cron/ using docker-compose.

    The rails official image does not have ssh enabled so I cannot just have the cron container to ssh into the web container and run the scripts.

    Does docker-compose have a way for a container to gain a shell into a linked container to execute some commands?

  • How to fit docker in this architecture?
  • Docker open outside ports - not opening the good ones
  • Ruby and Rails “path not found” when installed using RVM on Docker
  • Docker will not send auth headers over HTTP
  • jekyll not updating static CSS, HTML files in docker development container
  • Why is Docker OS image size so small?
  • One Solution collect form web for “Using docker-compose (formerly fig) to link a cron image”

    What actually would you like to do with your containers? If you need to access some objects from container’s file system, you should just mount the volume to the ancillary container (consider --volumes-from option).

    Any SSH interaction between containers is considered as a bad practice (at least since docker 1.3, when docker exec has been implemented). Running more than one process inside the container (e.g. smth but the postgres or rails in your case) will result in a large overhead: in order to have a sshd along with rails you’ll have to deploy something like supervisord.

    But if you really need to provide some kind of nonstandard interaction between the containers and you’re sure that you really need it, I would suggest you to use one of the full-featured docker client libraries (like docker-py). It will allow you to launch docker exec in a programmable way.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.