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

  • Best workflow for developing and debugging - initially deploy in a docker environment
  • Docker error when uploading image
  • MongoDB is unable to write to a local database in docker from boot2docker
  • jenkins 'execute script' build step Error: /bin/docker: Permission denied
  • Docker with WebHDFS
  • Galera Cluster Rancher Node Scaling Issue
  • 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?

  • Use github private repo deploy key inside build stage in docker for npm install
  • Xdebug (inside Docker container) ignoring XDEBUG_CONFIG environment variable
  • Can't access to lite-server in docker container
  • session replication using AWS tomcat and RDS
  • How do you manipulate tags in docker registry 2.0 and the v2 API?
  • Can't run a docker container on kubernetes in the interactive mode
  • 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.