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:


  • How do I get AWS credentials in the AWS ECS docker container?
  • Docker Anonymous Voumes
  • docker ps shows empty list
  • Getting error installing nodejs when building from docker
  • Console PHP script runs differently when executes through docker exec or through PhpStorm
  • Install pip in docker
  • db:
      image: postgres
        - pgdata:/var/lib/postgresql/data
      build: .
      command: bundle exec rails s -b
        - .:/usr/src/app
        - "3011:3000"
        - db


    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 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?

  • Setting arguments in docker-compose file
  • Runc Containerd Check pointing support
  • what's the best approach to avoid rails gem conflict
  • How to run command during Docker build which requires a tty?
  • Docker run rm with rest API
  • docker command not found even though installed with apt-get
  • 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.