Alberto Bonsanto
Alberto Bonsanto

Reputation: 18022

No such file or directory while running docker

I have a python file server.py that simply reads LOGS_PATH environment variable and sets uses it to create the target's logs directory.

logs_path = os.getenv("LOGS_PATH", "/logs/proxy.log")
fileHandler = logging.FileHandler(logs_path)

My docker file has the following, notice that I create the logs directory and the proxy.log file.

EXPOSE 8000
CMD mkdir /logs
CMD touch /logs/proxy.log

CMD python server.py

Then I build the docker image and run it, as follows.

docker build -t rank
docker run --rm -it --net=host -p 8000:8000 --env-file=.env-co --name=rank rank

But when I run it, it blows up. It says IOError: [Errno 2] No such file or directory: '/logs/proxy.log'

Upvotes: 2

Views: 1196

Answers (1)

Robert
Robert

Reputation: 36733

CMD and RUN are different things. Use as this:

EXPOSE 8000
RUN mkdir /logs
RUN touch /logs/proxy.log

CMD python server.py

CMD is the command that represents the container when running, an image can have only one CMD (the last one is the only valid). RUN is excuted when you do docker build.

Upvotes: 2

Related Questions