cweagans / docker-bg-sync

A container that syncs files between two configurable directories.
224 stars 39 forks source link

Not convenient with Nginx #3

Closed michaelalhilly closed 7 years ago

michaelalhilly commented 7 years ago

I'm running the following containers: Nginx:latest Php-fpm-7.0 MariaDB:latest

I was mounting a WordPress directory to both Nginx and PHP and a MySQL directory to MariaDB. I updated my environment to use bg-sync to create separate volumes for each container above to manage syncing.

I got everything working and it indeed sped thing up. Some pages were still too slow but there was improvement.

Unfortunately, the Nginx container requires the WordPress directory to be mounted before it starts otherwise a restart is required. As you know a restart will stop the container and the sync will be broken. I couldn't figure out a workaround to get all containers up on their own.

I had to add supervisor to the Nginx container so I could log in and start Nginx manually after the WP directory was fully synced. This allowed me to test the performance.

I appreciate your effort in trying to create a workaround for this issue. Hopefully the Docker team will figure it out soon.

leonardola commented 7 years ago

@michaelalhilly do you have a COPY instruction inside your Dockerfile? You could copy your wordpress directory on build and then unisson resync when up and running, no restarts needed

michaelalhilly commented 7 years ago

@leonardola Hmm... Unfortunately the directory to sync is not static and is based on an argument passed to the docker run command so I can't set it within the image.

Thanks for the suggestion though.

derimagia commented 7 years ago

Sounds like you just need to add a "wait until ready" script to the top of your nginx. This is often used for checking if a database is ready, but you can use if for this.

See https://docs.docker.com/compose/startup-order/

cweagans commented 7 years ago

Sorry for the slowness here. I wasn't being notified of new issues on this repo for some reason. In any case, I'd recommend a wait script as @derimagia suggested. If you can supply a docker compose file that demonstrates your problem, I can poke at it a bit and see if there's a reasonable way to work around this in bg-sync.

michaelalhilly commented 7 years ago

@derimagia @cweagans Thanks for the suggestion. A simple bash script to wait for bg-sync to complete sounds like a good solution. I'm not working with that particular image at the moment but will post my script here when I get it working.