Skip to content

Instantly share code, notes, and snippets.

@leoricklin
Last active September 30, 2022 09:23
Show Gist options
  • Save leoricklin/9a12555d8178f06cd516af43a1f9af96 to your computer and use it in GitHub Desktop.
Save leoricklin/9a12555d8178f06cd516af43a1f9af96 to your computer and use it in GitHub Desktop.

Ubuntu

% sudo apt install docker.io
% sudo systemctl enable --now docker
% sudo docker --version
% service docker status
% sudo docker run hello-world
% sudo usermod -aG docker $USER
% docker run hello-world
  • sudo nano /etc/apt/apt.conf
Acquire::http::Proxy "http://192.168.11.61:3128";
Acquire::https::Proxy "http://192.168.11.61:3128";
  • sudo apt update -y

  • sudo systemctl edit docker

[Service]
Environment="HTTP_PROXY=http://192.168.11.61:3128"
Environment="HTTPS_PROXY=http://192.168.11.61:3128"
  • cat /etc/systemd/system/docker.service.d/override.conf

  • sudo systemctl daemon-reload

  • sudo systemctl show docker --property Environment

  • sudo systemctl restart docker

% sudo apt install docker-compose
% docker-compose -v
Docker config
$ cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
http_proxy="http://XXX.com:80/"
HTTP_PROXY="http://XXX.com:80/"
https_proxy="http://XXX.com:80/"
HTTPS_PROXY="http://XXX.com:80/"
  • start up dockerd
% source /bin/docker-service; echo $DOCKER_HOST
% docker run --rm hello-world
  • shutdown dockerd
% PID=`ps -ef|grep dockerd|grep -v "sudo"|grep -v "grep"|awk -F" " {'print $2'}`; echo $PID
root     23484 23483  1 11:43 pts/3    00:00:00 dockerd
% sudo kill -9 $PID; rm /mnt/wsl/shared-docker/docker.sock

Install Docker Desktop on Windows Home

Unnstall WSL
dism.exe /online /Disable-Feature /featurename:Microsoft-Windows-Subsystem-Linux /norestart
dism.exe /online /Disable-Feature /featurename:VirtualMachinePlatform /norestart
Install WSL 2
$ dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

$ dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

$ wsl --set-default-version 2
  • then reboot
  • Once your distribution is installed, click the X.appx again to launch it
  • Ubuntu-20.04
leorick, worknumber
$ ls C:\Users\leoricklin\AppData\Local\Packages\Cano*
$ wsl --list --all -v
$ wsl --setdefault Ubuntu-20.04
$ wsl --export Ubuntu-20.04 ubuntu.tar
$ mkdir /APP/WSL; cd /APP/WSL
$ wsl --import ubuntuphp ./ubuntuphp ubuntu.tar
$ wsl --distribution ubuntuphp

Config Docker

$ rm "/users/XXX/AppData/Roaming/Docker"
  • Starting Docker
    • Docker -> Setting -> Resources -> Proxies
    • Docker -> Setting -> Resources -> WSL Integration -> Enable Integration
    • Service -> Restarting LxssManager (and wait for 3 minutes)
    • Windows Start -> Ubuntu-20.04
    • Windows Start -> Docker Desktop

cmds

% docker exec -it -e VAR=1 dbt bash

docker-compose

$ tree
.
├── Dockerfile
├── app.py
├── docker-compose.yml
└── requirements.txt
  • Dockerfile
FROM python:3.7.0-alpine3.8

WORKDIR /usr/src/app

COPY requirements.txt ./

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

ENV FLASK_APP=app.py

CMD flask run --host=0.0.0.0
  • app.py
from flask import Flask, request, jsonify
from redis import Redis

app = Flask(__name__)
redis = Redis(host="redis", db=0, socket_timeout=5, charset="utf-8", decode_responses=True)

@app.route('/', methods=['POST', 'GET'])
def index():

    if request.method == 'POST':
        name = request.json['name']
        redis.rpush('students', {'name': name})
        return jsonify({'name': name})

    if request.method == 'GET':
        return jsonify(redis.lrange('students', 0, -1))
  • requirements.txt
flask
redis<3.0.0
  • docker-compose.yml
version: "3"

services:
  app:
    build: .
    image: takacsmark/flask-redis:1.0
    environment:
      - FLASK_ENV=development
    ports:
      - 5000:5000

  redis:
    image: redis:4.0.11-alpine
  • cmd
% docker-compose up -d

Docker Hub

  • allspark: spark-2.3
docker pull jupyter/all-spark-notebook:3b1f4f5e6cc1
GID=`grep vboxsf /etc/group|awk -F":" '{print $3}'`; \
docker run  \
 --memory=1024m \
 --cpus=0.9 \
 --detach \
 --publish 8890:8888 \
 --publish 4040:4040 \
 --publish 9000:9000 \
 --user root \
 --name "allspark" \
 -v /mnt/work:/home/jovyan/work \
 --env NB_GID=${GID} \
 --env JUPYTER_ENABLE_LAB=yes \
 --env GRANT_SUDO=yes \
 jupyter/all-spark-notebook:3b1f4f5e6cc1 \
 start-notebook.sh \
 --NotebookApp.password='sha1:c47b3322a3ee:74908547b0e99449de557de82f64e72cd6051acb'
  • ds
docker pull jupyter/datascience-notebook:d8ebb0d1d552
GID=`grep vboxsf /etc/group|awk -F":" '{print $3}'`; \
docker run  \
 --memory=1024m \
 --cpus=0.9 \
 --detach \
 --publish 8890:8888 \
 --publish 4040:4040 \
 --publish 9000:9000 \
 --user root \
 --name "ds" \
 -v /mnt/work:/home/jovyan/work \
 --env NB_GID=${GID} \
 --env JUPYTER_ENABLE_LAB=yes \
 --env GRANT_SUDO=yes \
 jupyter/datascience-notebook:d8ebb0d1d552 \
 start-notebook.sh \
 --NotebookApp.password='sha1:c47b3322a3ee:74908547b0e99449de557de82f64e72cd6051acb'
docker container start ds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment