-1

How can we create a simple docker file that can run mysql database and execute scripts present in some folder
like scripts-folder,
then run python application which will use this mysql database internally.

Currently, I have a Dockerfile to create mysql docker image and run scripts on it, but i don't want to create a seperate docker image for database work.

# Derived from official mysql image (our base image)
FROM mysql
# Add a database
ENV MYSQL_DATABASE mydatabase
# Add the content of the sql-scripts/ directory to your image
# All scripts in docker-entrypoint-initdb.d/ are automatically
# executed during container startup
COPY ./sql-scripts/ /docker-entrypoint-initdb.d/


But, I need to have only 1 ubuntu docker image that should run both mysql and python application internally.

Akram
  • 234
  • 2
  • 2

1 Answers1

0

Try adding these lines

RUN sudo apt-get update
RUN sudo apt-get install python
COPY <path/to/your/script.py>
CMD [ "python3", "script.py" ]

More information:

Dockerize python app

Install python into a docker image

xhenrique
  • 153
  • 1
  • 8
  • i don't want to create a seperate docker image for database work. – Akram Oct 09 '19 at 09:20
  • I know, this is why i didn't tell you to create a new dockerfile, i told you to ADD the lines into your mysql dockerfile. – xhenrique Oct 09 '19 at 10:03
  • are you telling me to build a mysql image and add python code mysql image, is that your answer??? – Akram Oct 09 '19 at 12:30
  • I'm telling you to build your image with the requirements to run your python application, your docker image is probably a unix-like system, meaning you can access the shell inside and do whatever you want, the MySQL database is just one thing running, you can run more them one if your image has the everything it needs – xhenrique Oct 09 '19 at 16:03
  • Sir, i have tried that but mysql image is not a server hosting image, so runs the API but don't host it as well as mysql is not connecting. – Akram Oct 10 '19 at 09:55