简体   繁体   中英

visibility of python output from bash

I've python code that includes tqdm code. the bash build docker image and container however I can't see any output from the container(in CLI).

#!/bin/sh
docker build . -t traffic
docker run -d --name traffic_con traffic
docker wait traffic_con
docker cp -a traffic_con:/usr/TrafficMannager/out/data/. ./out/data/
docker rm /traffic_con
docker rmi /traffic

I've tried to run the container on interactive mode (-it) however it's throwing an error

[EDIT:] Docker file:

FROM cityflowproject/cityflow

# Create a folder we'll work in 
WORKDIR /usr/TrafficMannager

# Upgrade installed packages
RUN apt-get update && apt-get upgrade -y && apt-get clean

# Install vim to open & edit code\text files
RUN apt-get install -y vim

# Install all python code depentences
RUN pip install gym && \
    pip install numpy && \
    pip install IPython && \
    pip install torch && \
    python -m pip install python-dotenv &&\
    pip install tqdm

COPY . .

CMD chmod u+x script/container_instructions.sh; ./script/container_instructions.sh

container_instructions:

#!/bin/sh
pip install lib/extern/CityFlow/.
python main.py

You run the Docker container in the background, then immediately docker wait for it. If you run the container in the foreground instead, you'll see its output on stdout, and the docker run command will complete when the container exits.

docker run --name traffic_con traffic  # without -d

Given the wrapper script you show, you may find this setup much easier to run in a Python virtual environment. Ignore all the Docker parts and run:

python3 -m venv venv
./venv/bin/pip install gym numpy IPython torch python-dotenv tqdm lib/extern/CityFlow
./venv/bin/python3 main.py

The script will directly write to ./out/data on the host system, without the long-winded privileged script to copy data out.

If you really do need a container here, you can also mount the output directory into the container to avoid the manual copy step.


#!/bin/sh
docker build . -t traffic
docker run --rm -v "$PWD/out/data:/usr/TrafficMannager/out/data" traffic
docker rmi traffic

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM