- Deployment with Docker
- Srdjan Grubor
- 302字
- 2021-07-02 23:22:14
Putting it all together
We're nearly done! The last thing we need to do is start Python's built-in HTTP server module when our container starts:
CMD [ "python3", "-m", "http.server" ]
With everything in place, we can build and start our new container:
$ docker build -t python_server .
Sending build context to Docker daemon 16.9kB
Step 1/14 : FROM python:3
---> 968120d8cbe8
<snip>
Step 14/14 : CMD python3 -m http.server
---> Running in 55262476f342
---> 38fab9dca6cd
Removing intermediate container 55262476f342
Successfully built 38fab9dca6cd
Successfully tagged python_server:latest
$ docker run -d \
-p 8000:8000 \
--rm \
python_server
d19e9bf7fe70793d7fce49f3bd268917015167c51bd35d7a476feaac629c32b8
We can cross our fingers and check what we have built by accessing http://localhost:8000:

It works! Clicking on the test.txt shows the correct Just a test string and README.md that we fetched from GitHub downloads just fine when clicked. With all of the functionality there, what is in the external/ directory?

If the volume is empty, it is really no surprise that our directory here is empty too. How about we see whether we can mount some files from our host into this directory:
$ # Kill our old container that is still running
$ docker kill d19e9bf7
d19e9bf7
$ # Run our image but mount our current folder to container's
$ # /srv/www/html/external folder
$ docker run -d \
-p 8000:8000 \
--rm \
-v $(pwd):/srv/www/html/external \
python_server
9756b456074f167d698326aa4cbe5245648e5487be51b37b00fee36067464b0e
Here, we are mounting our current directory ($(pwd)) to our /srv/www/html/external target with our -v flag. So what does http://localhost:8000/external look like now? Do we have our files visible?

Indeed we do - our service works exactly as we expect it to! A real service written from scratch!
With a working service under our belt, we should now be able to continue our journey into Docker in the next chapter by scaling our containers.
- 輕松學(xué)C語言
- 人工智能超越人類
- 數(shù)據(jù)運(yùn)營之路:掘金數(shù)據(jù)化時代
- 精通Excel VBA
- 數(shù)據(jù)庫原理與應(yīng)用技術(shù)
- 基于ARM 32位高速嵌入式微控制器
- Cloudera Administration Handbook
- 網(wǎng)站前臺設(shè)計綜合實(shí)訓(xùn)
- 精通LabVIEW程序設(shè)計
- INSTANT Adobe Story Starter
- 簡明學(xué)中文版Photoshop
- Mastering Ansible(Second Edition)
- C#求職寶典
- Embedded Linux Development using Yocto Projects(Second Edition)
- 項目實(shí)踐精解:C#核心技術(shù)應(yīng)用開發(fā)