While trying to debug a RUN statements in my Dockerfile, I attempted to redirect output to a file in a bound volume (./mongo/log
).
To my surprise I was unable to create files via the RUN command, or to pipe the output of another command to a file using the redirection/appending (>
,>>
) operators. I was however able to perform the said task by logging in the running container via docker exec -ti mycontainer /bin/sh
and issuing the command from there.
Why is this behaviour happening? How can I touch file in the Dockerfile / redirect output to a file or to the console from which the Dockerfile is run?
Here is my Dockerfile:
FROM mongo:3.4
#Installing NodeJS
RUN apt-get update && \
apt-get install -y curl && \
curl -sL https://deb.nodesource.com/setup_6.x | bash - && \
apt-get install -y nodejs
#Setting Up Mongo
WORKDIR /var/www/smq
COPY ./mongo-setup.js mongo-setup.js
##for testing
RUN touch /var/log/node.log && /
node --help 2>&1 > /var/log/node.log
##this was the command to debug
#RUN node mongo-setup.js > /var/log/mongo-setup.log 2> /var/log/mongo-setup.error.log
Here an excerpt from my docker-compose.yml:
mongodb:
build:
context: ./
dockerfile: ./mongodb-dockerfile
container_name: smqmongodb
volumes:
- /var/lib/mongodb/data
- ./mongo/log/:/var/log/
- ../.config:/var/www/.config
--no-cache=true
, as you can learn about in the link above), I would suggest that you review the way you create your Dockerfile to embrace and leverage the caching capabilities.docker-compose down && docker-compose build --no-cache && docker-compose up --force-recreate;
, I still do not have a file. Let me know what you think.