It is mostly (like a 100%) stolen from here
FROM ubuntu:16.04
RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential
COPY src/* /app/
WORKDIR /app
RUN pip install -r requirements.txt
ENTRYPOINT ["python"]
CMD ["app.py"]
Oh, and make sure that your (in my case flask) app will listen on all ifaces:
# your beautiful code here
if __name__ == "__main__":
app.run(debug=True,host='0.0.0.0')
For dev envs, when the environment variables of the mysql base image are not enough:
FROM mysql:5.7
RUN mkdir -p /docker-entrypoint-initdb.d
COPY initdb/01_create_some_crud_user.sql /docker-entrypoint-initdb.d/01_create_some_crud_user.sql
COPY initdb/02_insert_some_data.sql /docker-entrypoint-initdb.d/02_insert_some_data.sql
Shell scripts, SQL files, archived (tar) SQL files in /docker-entrypoint-initdb.d
will be executed at build time by the base mysql
image (which is strangly not documented enywhere but extremely useful). I could have used a volume for that, but, you know... this is a Windows machine.
Anyway, after that you could compose it like:
version: '3'
services:
mysql:
build:
context: .
dockerfile: Dockerfile
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: my_db
MYSQL_USER: superuser
MYSQL_PASSWORD: sa
MYSQL_RANDOM_ROOT_PASSWORD: true
Some note: the stuff in compose file environment
section will create a superuser for the DB. This is done by the mysql
base image.
The scripts from the Dockerfile
will create a user with only INSERT,SELECT,UPDATE,DELETE
privileges, just like in a production environment.
Watch out! Keep in mind that docker-compose will only rebuild your images if you are using an image
and you changed the tag. Otherwise when you change either the docker-compose.yml
or the referenced Dockerfile
then you have to remove the old images either with docker image rm
or docker-compose rm -vf
.