Skip to content
This repository has been archived by the owner on Nov 4, 2022. It is now read-only.

Added Docker - Corsi GNU/Linux Avanzati 2016 #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
318 changes: 318 additions & 0 deletions Corsi GNU Linux Avanzati/Docker/Notebooks/Demo.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,318 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Demo notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Hello world"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"scrolled": false
},
"outputs": [],
"source": [
"docker run alpine /bin/echo \"Hello, World\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Interactive session (run in a terminal)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# docker run -i -t alpine /bin/sh"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Basic container managment"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"docker run --name \"hello_world\" -d alpine /bin/sh -c \"while true; do echo hello world; sleep 1; done\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### List all containers (formatted)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"docker ps -a --format \"ID:{{.ID}} Name:{{.Names}} Image:{{.Image}} cmd:{{.Command}} Status:{{.Status}}\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Delete all exited containers"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"docker rm \"$(docker ps --filter status=exited --format \"{{.ID}}\")\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### View `hello_world` logs"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"docker logs hello_world | tail -5"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Building containers"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Build Up1-Docker"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# docker build -t fcremo/up1 ."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run it"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"docker run -e \"API_KEY=random1\" -e \"DELETE_KEY=random2\" \\\n",
"--name up1 -p 8080:9000 -v /path/to/local/storage/:/srv/Up1/i/ fcremo/up1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Connecting containers"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a new network"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"docker network create mattermost-net"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Start postgres"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"docker run --name mattermost-postgres --net mattermost-net -d \\\n",
" --env 'POSTGRES_USER=mattermost' --env 'POSTGRES_PASSWORD=password' \\\n",
" --volume /tmp/postgres:/var/lib/postgresql postgres"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Inspect the container to verify it's connected"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"docker inspect mattermost-postgres | jq \".[].NetworkSettings.Networks\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"See if the container is reachable"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"docker run --rm --net mattermost-net alpine /bin/ping -c 3 mattermost-postgres"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Start mattermost"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"docker run --name mattermost -d --net mattermost-net \\\n",
" --volume /tmp/mattermost:/opt/mattermost/data --publish 8080:80 \\\n",
" --env 'DB_ADAPTER=postgres' --env 'DB_HOST=mattermost-postgres' \\\n",
" --env 'DB_USER=mattermost' --env 'DB_PASS=password' \\\n",
" jasl8r/mattermost"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Mattermost with docker-compose"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Get docker-compose.yml"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"wget \"https://raw.githubusercontent.com/jasl8r/docker-mattermost/master/docker-compose.yml\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"docker-compose up"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Bash",
"language": "bash",
"name": "bash"
},
"language_info": {
"codemirror_mode": "shell",
"file_extension": ".sh",
"mimetype": "text/x-sh",
"name": "bash"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Loading