Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override entrypoint: can't run any command after "docker-entrypoint.sh mysqld" #312

Closed
m0onspell opened this issue Jul 27, 2017 · 3 comments

Comments

@m0onspell
Copy link

Version: 8.0.1.

I need to override entrypoint to be able to launch cron service, but at the same time I want to preserve existing entrypoint instruction. So I tried different options, and the last thing I did was:

ENTRYPOINT ["/bin/sh", "-c"]
CMD ["docker-entrypoint.sh mysqld && cron"]

Container launched, mysql was running, but cron service didn't launch. If I swap command places, everything works as expected:

CMD ["cron && docker-entrypoint.sh mysqld"]

Does docker-entrypoint.sh somehow strips && part? Is that possible for shell script to do such things? I am not a linux expert, just curious.

@yosifkit
Copy link
Member

No, it doesn't even know that the && cron exists. The /bin/sh parses the line and runs the first half. Once that first half exits with a successful exit code it will run the second half. The docker-entrypoint script is designed to be a foreground process, so it never exits. Cron, on the other hand, seems to be written as a daemon, so it forks a child and exits. Be warned that if cron ever crashes there would be nothing in the container that would restart it. It would be better to use a second container that just runs cron, or the host cron that does a docker exec, or add a process supervisor like supervisord.

@m0onspell
Copy link
Author

@yosifkit Ah, I see, thanks for clarification. I need a cron to run mysldump every day and send it to google drive. I don't like supervisord approach because it requires extra configuration and may introduce new issues, but that's probably how it should be done ideally. For separate container approach: I wanted to do that, but I wasn't able to figure out, how can I access mysqldump from external container. The only thing that comes into mind is to share mysqldump by using volume. Or make another container for mysqldump only, and then invoke it with remote host params. But either of those ways have obvious disadvantages.
Can you share your opinion?

@yosifkit
Copy link
Member

I'd probably just run a new mysql container that dumps to a volume mounted from the host and then have it upload to drive. I'd probably even want to have a specific user in the database that has access for dumping but not anything else.

FROM mysql:8.0.1
# install any tools needed to upload to google drive
RUN apt-get update \
	&& apt-get install -y --no-install-recommends ca-certificates wget \
	&& rm -rf /var/lib/apt/lists/*
# make sure file is chmod +x locally
COPY backup-mysql.sh /usr/local/bin/
CMD ["backup-mysql.sh"]
#!/bin/bash
set -e
slqFile="$(date +%Y-%m-%d).sql.gz"

# or maybe a file with the password via docker secrets
mysqldump -hmysql -ubackup -p"$SQL_PASSWORD" --all-databases | gzip -c > "/backup/$sqlFile"

# upload to google drive
#wget ...

And then run it from cron or as a docker service that restarts on any exit with a delay of 23 or 24 hours.

$ docker run --rm -v /path/to/local/backups/:/backup/ -e SQL_PASSWORD=secret --link name-of-msyql-container:mysql mysql-backup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants