Skip to content

Instantly share code, notes, and snippets.

@cj-praveen
Last active January 2, 2026 11:18
Show Gist options
  • Select an option

  • Save cj-praveen/68e265db39baab42d8406f1919352b23 to your computer and use it in GitHub Desktop.

Select an option

Save cj-praveen/68e265db39baab42d8406f1919352b23 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 68,
"id": "47889aba",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Reading package lists... Done\n",
"Building dependency tree... Done\n",
"Reading state information... Done\n",
"docker.io is already the newest version (20.10.24+dfsg1-1+deb12u1+b2).\n",
"0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n"
]
}
],
"source": [
"# Install Docker on Linux\n",
"!sudo apt install -y docker.io"
]
},
{
"cell_type": "code",
"execution_count": 69,
"id": "342e9b4d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Synchronizing state of docker.service with SysV service script with /lib/systemd/systemd-sysv-install.\r",
"\r\n",
"Executing: /lib/systemd/systemd-sysv-install enable docker\r",
"\r\n"
]
}
],
"source": [
"# Enable Docker\n",
"!sudo systemctl enable docker"
]
},
{
"cell_type": "code",
"execution_count": 70,
"id": "7239fce0",
"metadata": {},
"outputs": [],
"source": [
"# Start Docker services\n",
"!sudo systemctl start docker"
]
},
{
"cell_type": "code",
"execution_count": 71,
"id": "2c8a8c26",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Docker version 20.10.24+dfsg1, build 297e128\r\n"
]
}
],
"source": [
"# Check the docker version\n",
"!docker --version"
]
},
{
"cell_type": "code",
"execution_count": 72,
"id": "f23b6b5b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Using default tag: latest\n",
"latest: Pulling from library/nginx\n",
"Digest: sha256:ca871a86d45a3ec6864dc45f014b11fe626145569ef0e74deaffc95a3b15b430\n",
"Status: Image is up to date for nginx:latest\n",
"docker.io/library/nginx:latest\n"
]
}
],
"source": [
"# Pull nginx docker image\n",
"!docker pull nginx"
]
},
{
"cell_type": "code",
"execution_count": 73,
"id": "944396ab",
"metadata": {},
"outputs": [],
"source": [
"%%bash\n",
"# Open and write Dockerfile\n",
"cat <<EOF > Dockerfile\n",
"FROM python:3.11-alpine\n",
"WORKDIR src/\n",
"copy main.py .\n",
"CMD [\"python3\", \"main.py\"]\n",
"EOF"
]
},
{
"cell_type": "code",
"execution_count": 74,
"id": "cf585547",
"metadata": {},
"outputs": [],
"source": [
"# Open and write main.py\n",
"!echo 'print(\"Hello, World!\")' > main.py"
]
},
{
"cell_type": "code",
"execution_count": 75,
"id": "b1f2e9c2",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Sending build context to Docker daemon 16.9kB\n",
"Step 1/4 : FROM python:3.11-alpine\n",
" ---> ff629aaf2b0a\n",
"Step 2/4 : WORKDIR src/\n",
" ---> Using cache\n",
" ---> 2ec840390921\n",
"Step 3/4 : copy main.py .\n",
" ---> Using cache\n",
" ---> 0ff4d1cb3c24\n",
"Step 4/4 : CMD [\"python3\", \"main.py\"]\n",
" ---> Using cache\n",
" ---> c5c81b90c75c\n",
"Successfully built c5c81b90c75c\n",
"Successfully tagged hello-world:latest\n"
]
}
],
"source": [
"# Build Docker image for your project\n",
"!docker build -t hello-world ."
]
},
{
"cell_type": "code",
"execution_count": 76,
"id": "5e255083",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"REPOSITORY TAG IMAGE ID CREATED SIZE\r\n",
"hello-world latest c5c81b90c75c 4 hours ago 58.6MB\r\n",
"<none> <none> 45867f853d0b 4 hours ago 58.6MB\r\n",
"<none> <none> f45769532ce1 6 hours ago 58.6MB\r\n",
"nginx latest 759581db3b0c 3 days ago 172MB\r\n",
"python 3.11-alpine ff629aaf2b0a 2 weeks ago 58.6MB\r\n"
]
}
],
"source": [
"# List available docker images\n",
"!docker images"
]
},
{
"cell_type": "code",
"execution_count": 77,
"id": "215c1247",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello, World!\r\n"
]
}
],
"source": [
"# Run the Docker image 'hello-world'\n",
"!docker run hello-world"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2032ab1c",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment