👉 Making your life easier:)

The name docker is used about:

  1. Docker containerization technology
    • a container makes in possible to package and isolate applications with their entire runtime environment
  2. The docker open source community
  3. The company docker
    Also see Redhat's post

Installation

Follow 🐋 for
For Linux, Windows, Apple
Or
Docker desktop
Or install
podman
for your distro

Getting started

docker run hello-world
docker --help
A lot of options! The most important commands are
build, images, pull, run, exec, ps and stop

Getting started

IMPORTANT❗❗

Use docker autocomplete

It's often installed on bash etc
for powershell try this

Using containers 🐛

docker run -it ubuntu:latest
#-it=interactive pseudo terminal

then, in a different terminal

# shows the running containers
docker ps

finally attach on more shell

docker exec --it <CONTAINER ID OR NAME> /bin/bash

🏗️ Building Images

Making it easy for others to use your code❗

and

shipping code 🚢

🏗️ The Dockerfile

FROM python:3.8-slim

RUN pip install emoji

WORKDIR /app

COPY hello-docker.py ./

RUN useradd -u 999 non-root-user
USER non-root-user

ENTRYPOINT ["python"]
CMD ["hello-docker.py"]

Building and running the image

  1. Clone this presentation and go to the ./docker folder
  2. Run docker build . -t hello-docker:latest

Build tips

  • Order of instructions matters
  • Add the files needed .i.e not COPY . .
  • Try to build small final images, multi-stage build can be helpful

Build args & secrets

These are used during build:) but be careful with what you pass in, args are stored in the image history

docker history hello-docker:latest

instead use buildx secrets if needed

BUILD SECRETS(ssh)

Create a Dockerfile
FROM alpine/git

RUN apk add --no-cache openssh-client
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts

# Some private repo
RUN --mount=type=ssh git clone git@github.com:NIVANorge/STOP_import_GUI.git STOP
WORKDIR /git/STOP

CMD ["log"]
docker build --ssh default . -t secret-example
docker run secret-example

Finding images

In most cases you can find images on dockerhub.

For internal niva images you need to follow instructions on google cloud artifactory setup and go to the artifactory.

Running containers

  • default docker run hello-docker
  • cmd docker run -it hello-docker:latest :yarn:
  • entrypoint
docker run -it --entrypoint /bin/python hello-docker:latest

Configure the container

Config as ENV variables

  1. Using --env or -e
    docker run -e NIVA_ENV=1 hello-docker
  2. Using --env-file
    docker run --env-file .env hello-docker

Configure the container

mount file

docker run  -e FAVOURITE_PATH=/app/favorite.emojis \
--mount type=bind,source="$(pwd)"/favorite.emojis,target=/app/favorite.emojis,readonly \
hello-docker

docker compose

docker-compose -> docker compose

docker-compose has been rewritten to a Golang plugin for docker

docker compose install

  • Already installed if using Docker Desktop
  • For linux distro's see compose install
  • For thumbleweed 😎
zypper in docker-compose

The compose file

version: '3.5'
services:
  app:
    build: .
    entrypoint: shiny run --host 0.0.0.0 --port 6000 app.py
    environment:
      - SERVER=https://thredds.niva.no
      - DATASET=msource-inlet.nc
    ports:
      - "5000:6000"

Commands 🏗️

  • docker compose build
  • docker compose up
  • docker compose down --volumes
    ++ justrun docker compose help

Python shiny ☀️ app

Still in the ./docker folder run

docker compose up

and go to

http://localhost:5000/

Dockerbasen

compose example

👌