Skip to content

Instantly share code, notes, and snippets.

@ibnesayeed
Last active November 6, 2019 22:00
Show Gist options
  • Save ibnesayeed/9299087aa4509e3d28f821b6f3ae4247 to your computer and use it in GitHub Desktop.
Save ibnesayeed/9299087aa4509e3d28f821b6f3ae4247 to your computer and use it in GitHub Desktop.
$ ls
Dockerfile  linkextractor.py
$ cat linkextractor.py
#!/usr/bin/env python

import sys
import requests
from bs4 import BeautifulSoup

res = requests.get(sys.argv[-1])
soup = BeautifulSoup(res.text, "html.parser")
for link in soup.find_all("a"):
    print(link.get("href"))
$ cat Dockerfile
FROM       python
LABEL      maintainer="Sawood Alam <@ibnesayeed>"

RUN        pip install beautifulsoup4
RUN        pip install requests
COPY       linkextractor.py /app/
WORKDIR    /app
RUN        chmod a+x linkextractor.py

ENTRYPOINT ["./linkextractor.py"]
$ docker image build -t ibnesayeed/linkextractor .
Sending build context to Docker daemon  3.072kB
Step 1/8 : FROM       python
 ---> 02d2bb146b3b
Step 2/8 : LABEL      maintainer="Sawood Alam <@ibnesayeed>"
 ---> Using cache
 ---> dd89829b721d
Step 3/8 : RUN        pip install beautifulsoup4
 ---> Running in 6bbf59305fa9
Collecting beautifulsoup4
  Downloading https://files.pythonhosted.org/packages/3b/c8/a55eb6ea11cd7e5ac4bacdf92bac4693b90d3ba79268be16527555e186f0/beautifulsoup4-4.8.1-py3-none-any.whl (101kB)
Collecting soupsieve>=1.2 (from beautifulsoup4)
  Downloading https://files.pythonhosted.org/packages/81/94/03c0f04471fc245d08d0a99f7946ac228ca98da4fa75796c507f61e688c2/soupsieve-1.9.5-py2.py3-none-any.whl
Installing collected packages: soupsieve, beautifulsoup4
Successfully installed beautifulsoup4-4.8.1 soupsieve-1.9.5
WARNING: You are using pip version 19.2.3, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Removing intermediate container 6bbf59305fa9
 ---> a8dd8a35998a
Step 4/8 : RUN        pip install requests
 ---> Running in fa8f3870e362
Collecting requests
  Downloading https://files.pythonhosted.org/packages/51/bd/23c926cd341ea6b7dd0b2a00aba99ae0f828be89d72b2190f27c11d4b7fb/requests-2.22.0-py2.py3-none-any.whl (57kB)
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 (from requests)
  Downloading https://files.pythonhosted.org/packages/e0/da/55f51ea951e1b7c63a579c09dd7db825bb730ec1fe9c0180fc77bfb31448/urllib3-1.25.6-py2.py3-none-any.whl (125kB)
Collecting certifi>=2017.4.17 (from requests)
  Downloading https://files.pythonhosted.org/packages/18/b0/8146a4f8dd402f60744fa380bc73ca47303cccf8b9190fd16a827281eac2/certifi-2019.9.11-py2.py3-none-any.whl (154kB)
Collecting idna<2.9,>=2.5 (from requests)
  Downloading https://files.pythonhosted.org/packages/14/2c/cd551d81dbe15200be1cf41cd03869a46fe7226e7450af7a6545bfc474c9/idna-2.8-py2.py3-none-any.whl (58kB)
Collecting chardet<3.1.0,>=3.0.2 (from requests)
  Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
Installing collected packages: urllib3, certifi, idna, chardet, requests
Successfully installed certifi-2019.9.11 chardet-3.0.4 idna-2.8 requests-2.22.0 urllib3-1.25.6
WARNING: You are using pip version 19.2.3, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Removing intermediate container fa8f3870e362
 ---> f7c2a11244df
Step 5/8 : COPY       linkextractor.py /app/
 ---> 8a882e68e727
Step 6/8 : WORKDIR    /app
 ---> Running in ce9b241641d6
Removing intermediate container ce9b241641d6
 ---> e46946e052ee
Step 7/8 : RUN        chmod a+x linkextractor.py
 ---> Running in 3b995eeec865
Removing intermediate container 3b995eeec865
 ---> 71b85becc7f1
Step 8/8 : ENTRYPOINT ["./linkextractor.py"]
 ---> Running in 1806b44bcdaa
Removing intermediate container 1806b44bcdaa
 ---> aa5f2999d279
Successfully built aa5f2999d279
Successfully tagged ibnesayeed/linkextractor:latest
$ docker container run ibnesayeed/linkextractor https://example.com/
https://www.iana.org/domains/example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment