Running a simple web server in Docker?

I am trying to create a simple docker container that serves static html. I have the following Docker file:

FROM ubuntu # Install python3 RUN apt-get update RUN apt-get install -y python3 # Copy html ADD static/ /src RUN cd /src # Run http server on port 8080 EXPOSE 8080 CMD ["python3", "-m http.server 8080" 

However, when I build + run it, I get the following error:

 /usr/bin/python3: No module named http 

I tried the same steps through the interactive shell and they work fine, however, as soon as I use the Dockerfile, it fails.

+6
source share
2 answers

I think the CMD syntax is incorrect. I just tried and it works fine:

 FROM ubuntu # Install python3 RUN apt-get update RUN apt-get install -y python3 # Copy html ADD static/ /src RUN cd /src # Run http server on port 8080 EXPOSE 8080 CMD ["python3", "-m", "http.server", "8080"] 
+13
source

I had a problem with the accepted answer, in which problems with the network prevented me from starting the apt-get update on my corporate network.

However, the following Dockerfile worked, and I find it lighter than the ubuntu image, for something as simple as sharing static html files.

 FROM python:3.6.0-alpine ADD static/ /src WORKDIR /src EXPOSE 8080 ENTRYPOINT ["python3", "-m", "http.server", "8080"] 

Also, since this relates to the first question, will the following not work? I'm not sure I understand the advantage of hacking a command into an array.

 CMD python3 -m http.server 8080 
+1
source

Source: https://habr.com/ru/post/953712/


All Articles