Using docker-compose (formerly fig) to link a cron image
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
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?
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
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
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
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.