1

I want a docker container that runs a command for it's effects, and then it's fine to stop until I run it again.

I just want to run only this, to delete expired rows:

mysql --user=$MYSQL_USER --host=$MYSQL_HOST --database=$MYSQL_DB --password=$MYSQL_PASS -se "DELETE FROM sometable WHERE expiration < NOW();"

I've tried this:

FROM ?????

ENV MYSQL_USER=$MYSQL_USER
ENV MYSQL_HOST=$MYSQL_HOST
ENV MYSQL_PASS=$MYSQL_PASS
ENV MYSQL_DB=$MYSQL_DB

ENTRYPOINT mysql --user=$MYSQL_USER --host=$MYSQL_HOST --database=$MYSQL_DB --password=$MYSQL_PASS -se "DELETE FROM sometable WHERE expiration < NOW();"

and running it with:

docker run --name some-process \
-e MYSQL_USER=$MYSQL_USER \
-e MYSQL_PASS=$MYSQL_PASS \
-e MYSQL_HOST=$MYSQL_HOST \
-e MYSQL_DB=$MYSQL_DB \
-d some-image:latest

And I've tried many permutations of this, but, I'm really lost.

Any advice what my Dockerfile and docker run command should look like to run that?


EDIT:

I've tried so many things and gotten so many errors that I think it's futile to "fix" my attempts, and instead just solicit, "how do I have a container run mysql -se "DELETE ...""

But if it helps, here are some of the errors I've been getting ( i get the first one most frequently)

ERROR 2002 (HY000): Can't connect to local MySQL server through socket 

------

ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)

------

Error response from daemon: No such container:

------

docker: Error response from daemon: repository my-mysql-server not found: does not exist or no pull access.

------

ERROR: mysqld failed while attempting to check config

------

error: database is uninitialized and password option is not specified
2
  • What does what you've done result in? Looks reasonable enough to me. Commented Jun 22, 2017 at 21:34
  • So, what are the errors? You don't post any log or output. We don't know what the issue is. If you can edit the question to give some more output and debug information I can improve my answer. Commented Jun 23, 2017 at 1:25

1 Answer 1

1

You don't need to build an image to do this. You can just use the MySQL client in the official image:

docker run -it -e MYSQL_PWD=yourpass mysql:5.6 mysql -h $MYSQL_HOST --port 3306 -u youruser -e "DELETE FROM sometable WHERE expiration < NOW();"
Sign up to request clarification or add additional context in comments.

4 Comments

thanks that definitely works locally; in this case though I need to deploy to ECS so I think it needs to be a docker image
Why? Does ECS not allow you to specify an image, environment variables, and command?
well, perhaps... I'm trying now but getting ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111) (I'm trying this locally, and a mysql service is running in a docker container)
Well, it won't be able to connect to 127.0.0.1, that will be the container itself (unless you are doing some custom networking or using host net mode). You need to pass the actual MySQL host to -h.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.