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

  • Docker Container Networking with Docker-in-Docker
  • Debian Host: CTRL + P + Q doesn't keep container alive
  • How to enable Spark mesos docker executor?
  • IntelliJ IDEA and docker plugin
  • Installing a web application in a Docker container: dial unix /var/run/docker.sock: no such file or directory
  • Kubernetes Docker Multi Node Setup issues
  • 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?

  • Eliminate mess with docker swarm mode loadbalancer, consul and external load balancer
  • Error running Docker node container on Windows 10
  • Move docker-machine to another computer
  • Update odoo custom module using docker-compose
  • Error when running application at the container -Docker
  • pip install letencrypt, hwo do I know which packages are needed?
  • 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.