I have a directory with one simple HTML file (name: index.html) which displays some basic text. I run the python command:
python -m SimpleHTTPServer 7000
to run a server, at port 7000, in the same directory to display the page in a browser.
Now I want to be able to dockerize this process and need help with that.
Basically, the dockerfile should run a server at 7000 port using this python command and then display the html on a browser.
What I thought of:
FROM ubuntu:14.04
COPY index.html
FROM python:latest
EXPOSE 80
CMD ["python SimpleHTTPServer 7000", "-m"]
Also, how would I build and run this file once it is done?
I am pretty sure this won't work but since I am new to this, I don't know how to correct it.
Also, how would I build and run this file once it is done?
You were close. Several pointers:
Here are Dockerfile
variations for python 3:
FROM python:latest
COPY index.html /
EXPOSE 7000
CMD python -m http.server 7000
and python 2.7:
FROM python:2.7
COPY index.html /
EXPOSE 7000
CMD python -m SimpleHTTPServer 7000
alongside with build
docker build -t my-docker-image .
and run commnand:
docker run --rm -it --name my-docker-instance -p 80:7000 my-docker-image
After run you can go to http://localhost
to get container's port 7000 there, providing your host doen't run something on port 80 (remap if so).
Notes:
Edit: I see that b0gusb beat me to it :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With