How to rerun docker-compose after modifying containerized python script
Question:
Docker newbie question here.
I am working on containerizing my own Python script, following this tutorial and that tutorial.
I noticed that when I fix an error in my Python script (myscript.py), this change is not seen upon rerunning sudo docker-compose up
. I need to change the app name in docker-compose.yml (e.g. from my-awesome-app2 to my-awesome-app3) to get it to run.
I tried listing the available containers using sudo docker container ls -a
and then removing the unused containers with sudo docker rm <CONTAINER ID>
but this did not help.
How can I get docker-compose to see the changes made to the Python script, without having to keep changing the Dockerfile?
Here is my docker-compose.yml:
version: "3"
services:
my-awesome-app3:
build:
context: .
Here is my Dockerfile:
FROM python:3.8.3
# Or any preferred Python version.
ADD myscript.py .
RUN pip3 install pywavelets scipy
CMD ["python", "./myscript.py"]
# Or enter the name of your unique directory and parameter set.
And here is myscript.py:
from scipy.misc import electrocardiogram
import pywt
import numpy as np
ecg = electrocardiogram()
FPData = ecg.reshape(10800,-1)
DWTcoeffs = pywt.wavedec(FPData[:,1], 'db4')
filtered_data_dwt=pywt.waverec(DWTcoeffs,'db4',mode='symmetric',axis=-1)
print(filtered_data_dwt)
Let’s say that I make a typo (print(filtered_data)
instead of print(filtered_data_dwt)
)… Rerunning sudo docker-compose up
will still trigger:
my-awesome-app2_1 | NameError: name ‘filtered_data’ is not defined
Answers:
Not enough reputation for a comment, but did you rebuild your container?
sudo docker compose up --rebuild
is one way of doing both in one go.
P.S. depending on your security restrictions, you can set it up to run without the need to prefix it with sudo
Docker newbie question here.
I am working on containerizing my own Python script, following this tutorial and that tutorial.
I noticed that when I fix an error in my Python script (myscript.py), this change is not seen upon rerunning sudo docker-compose up
. I need to change the app name in docker-compose.yml (e.g. from my-awesome-app2 to my-awesome-app3) to get it to run.
I tried listing the available containers using sudo docker container ls -a
and then removing the unused containers with sudo docker rm <CONTAINER ID>
but this did not help.
How can I get docker-compose to see the changes made to the Python script, without having to keep changing the Dockerfile?
Here is my docker-compose.yml:
version: "3"
services:
my-awesome-app3:
build:
context: .
Here is my Dockerfile:
FROM python:3.8.3
# Or any preferred Python version.
ADD myscript.py .
RUN pip3 install pywavelets scipy
CMD ["python", "./myscript.py"]
# Or enter the name of your unique directory and parameter set.
And here is myscript.py:
from scipy.misc import electrocardiogram
import pywt
import numpy as np
ecg = electrocardiogram()
FPData = ecg.reshape(10800,-1)
DWTcoeffs = pywt.wavedec(FPData[:,1], 'db4')
filtered_data_dwt=pywt.waverec(DWTcoeffs,'db4',mode='symmetric',axis=-1)
print(filtered_data_dwt)
Let’s say that I make a typo (print(filtered_data)
instead of print(filtered_data_dwt)
)… Rerunning sudo docker-compose up
will still trigger:
my-awesome-app2_1 | NameError: name ‘filtered_data’ is not defined
Not enough reputation for a comment, but did you rebuild your container?
sudo docker compose up --rebuild
is one way of doing both in one go.
P.S. depending on your security restrictions, you can set it up to run without the need to prefix it with sudo