Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jedevc/docker-dino-demo
🦕 Deploying a dinosaur web app using docker!
https://github.com/jedevc/docker-dino-demo
Last synced: about 1 month ago
JSON representation
🦕 Deploying a dinosaur web app using docker!
- Host: GitHub
- URL: https://github.com/jedevc/docker-dino-demo
- Owner: jedevc
- License: unlicense
- Created: 2019-11-21T16:46:52.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-03-20T02:30:45.000Z (over 3 years ago)
- Last Synced: 2023-03-01T22:31:30.416Z (over 1 year ago)
- Language: Python
- Size: 18.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Docker demo
**This is the demo from my slides [here](https://docs.google.com/presentation/d/1K7yt9h-T9BoDUA_im8-Tqd-ok1N-tJGDwSGo6hTQkO0/edit?usp=sharing).**
Let's deploy a flask web app in Docker!
## Startup
First let's build our image!
$ docker build . -t docker-dino
Now we can run it:
$ docker run -d docker-dino
69a3f27004e6c62c5227d594e87aa969b48eedf45448d6f62aaa7182f409371b
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
69a3f27004e6 docker-dino "/bin/sh -c 'gunicor…" 14 seconds ago Up 11 seconds 80/tcp sharp_darwinAnd we can now see our container is now running. But how can we actually
access it?To do that, we can restart our container, but this time expose port 80 from
the container to port 8080 on our host!$ docker kill 69a3f27004e6
69a3f27004e6
$ docker run -p 8000:80 -d docker-dino
74470db53fe64cc0b457afb1ba6552145f267c698ddaa28624a62832812d1a16
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
74470db53fe6 docker-dino "/bin/sh -c 'gunicor…" 2 seconds ago Up Less than a second 0.0.0.0:8000->80/tcp recursing_khoranaNow that the port is published, we can access our site:
$ curl localhost:8000
Hello World (and dinosaurs)!## File uploads
Let's try and send a file to our website.
$ curl http://localhost:8000/upload -F "[email protected]"
500 Internal Server Error
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
Uh oh! We got an internal server error!
Docker lets us peek inside the container to have a look what's going on.
$ docker logs 74470db53fe6
[2019-11-21 16:27:54 +0000] [6] [INFO] Starting gunicorn 20.0.0
[2019-11-21 16:27:54 +0000] [6] [INFO] Listening at: http://0.0.0.0:80 (6)
[2019-11-21 16:27:54 +0000] [6] [INFO] Using worker: sync
[2019-11-21 16:27:54 +0000] [10] [INFO] Booting worker with pid: 10
[2019-11-21 16:28:08,911] ERROR in app: Exception on /upload [POST]
Traceback (most recent call last):
...
File "/app/dino/dino.py", line 27, in upload
file.save(os.path.join(UPLOADS, out_filename))
...
FileNotFoundError: [Errno 2] No such file or directory: '/app/uploads/dino.txt'Aha! The directory we're trying to upload files to doesn't exist!
We'll fix this later in the Dockerfile, but for now, we'll use another
technique to patch the container while it's running!$ docker exec -it 74470db53fe6 /bin/bash
root@74470db53fe6:/app# ls
Pipfile Pipfile.lock README.md demo
root@74470db53fe6:/app# mkdir uploadsNow we want to exit the container with ctrl-d and we can try the upload again:
$ curl http://localhost:8000/upload -F "[email protected]"
Redirecting...
Redirecting...
You should be redirected automatically to target URL: /files/dino.txt. If not click the link.
Great! We should then be able to easily get the dinosaur:
$ curl http://localhost:8000/dinos/dino.txt
__
/oo\
| |
^^ (vvvv) ^^
\\ /\__/\ //
\\/ \//
/ \
| | ^
/ \___/ |
( ) |
\----------/ /
// \\_____/
W WWe can then patch our Dockerfile for future containers:
```Dockerfile
...
ENV UPLOADS_DIR=uploads/
RUN mkdir -p uploads/
...
```