-1

I have dockerfile like this

FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install -y software-properties-common vim
RUN add-apt-repository ppa:jonathonf/python-3.6
RUN apt-get update
RUN mkdir /app
WORKDIR /app
ADD test_write.py /app/    
RUN chmod 777 test_write.py
RUN python3.6 test_write.py
RUN cat media/test.txt

test_write.py script create test.txt file and write content to that file. Problem is when I run docker build everything runs fine but after when I log in to Docker container I cannot see test.txt file which is created by the script. Am I doing anything wrong?

this is output for test_write.py script. I can not write entire dockerfile here.. so just printing out output for test_write.py script command.

```

Removing intermediate container dec90eb251e5
Step 22/24 : RUN python3.6 test_write.py
 ---> Running in 96b8b7a9f6eb
Running ....
 ---> 555e4e86be11
Removing intermediate container 96b8b7a9f6eb
Step 23/24 : RUN cat media/test.txt
 ---> Running in 6ffd8a8e63e3
Written to file using docker ---> f502a63cd760
Removing intermediate container 6ffd8a8e63e3

```

mohan08p
  • 5,002
  • 1
  • 28
  • 36
Yogesh
  • 865
  • 6
  • 13
  • It this actually a [minimal, complete and verifiable example](https://stackoverflow.com/help/mcve)? How does `test_write.py` get into your container? I don't see any `ADD` or `COPY` statement in your Dockerfile. What's the actual output of `docker build` for this Dockerfile? – helmbert Feb 10 '18 at 16:28

2 Answers2

0

I copy/pasted your Dockerfile and get the following error.

Step 10/11 : RUN python3.6 test_write.py
 ---> Running in 4ef189b481ea
/bin/sh: 1: python3.6: not found
The command '/bin/sh -c python3.6 test_write.py' returned a non-zero code: 127

Not sure how you got it to work as written. Maybe try something like:

FROM python:3.6-stretch
RUN mkdir /app
WORKDIR /app
ADD test_write.py /app/    
RUN python test_write.py
RUN cat media/test.txt

Alternatively, comment out the last two lines of your Dockerfile and then start it up and run your python script manually to see if it works. Maybe it's writing the output file to a different location or something.

B. Johnson
  • 36
  • 3
  • I run python script manually after login to Docker container and it's creating the file but inside dockerfile it's not working. – Yogesh Feb 12 '18 at 05:52
0

Sorry, It was my mistake... in my docker-compose I was using volumes like this

volumes:
  - .:/app

so app directory contain the local directory structure inside docer after I run 'docker-compose up ' Sorry for posting invalid question

Yogesh
  • 865
  • 6
  • 13