Execute Python script inside a given docker-compose container
Solution 1:
First find out if you have python
executable in the container
:
docker exec -it rethink which python
If it exists, Use the absolute path
provided by which
command in previous step:
docker exec -it rethink /absolute/path/to/python src/app/db-install.py
If not, you can convert your python script
to bash script
, so you can run it without extra executables
and libraries
.
Or you can create a dockerfile
, use base image
, and install python
.
dockerfile:
FROM rethinkdb:latest
RUN apt-get update && apt-get install -y python
Docker Compose file:
rethink:
build : .
container_name: rethink
ports:
- 58080:8080
- 58015:28015
- 59015:29015