- Clone the repo
git clone https://github.com/jackie-yt-wang/docker-container-control-python.git
- Install Docker and run the Docker application
- Build Docker Image withe repo name
docker-image
and tag namev1
docker build -t docker-image:v1
- Run Docker Container using the image built
docker run --rm -t -d -v $(pwd)/input:/app/input -v $(pwd)/output:/app/output docker-image:v1
- Check if Docker Container is running by
docker ps
- Execute Docker with the running container
docker exet -it <id> pipenv run python3 script.py
Create a docker container for data process.
In the file, there are 2 folders (input and output) and 1 python script. There are 2 csv files (t1 and t2) in the input folder. What you need to do is create an image to generate a container, in the container, you will:
- Use the python script to read the data from input folder.
- Write the result data into output folder.
- The python script is in the container.
- The input and output folder are in the host, in other words, outside the container. What you need to do is to mount the 2 folders from host to the container.
- Try to make the container running first, and then run the python script. This means when you use
docker run
to start up the container, the python script will not run. The python script only runs when you give container an order with commanddocker exec
. - The python script is ready to use, and you don't need to change it. But if you want, you can change the script for your requirements.