Skip to content

Mauraza/academic-containers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Suse Academic Introduction to containers

Playing with CLI

  • Check you have installed docker or podman:
podman run hello-world
docker run hello-world
  • Run a container:
podman run -d --name mynginx nginx
docker run -d --name mynginx nginx
  • List the containers running:
podman ps
docker ps
  • Enter a running container:
podman exec -ti mynginx bash
docker exec -ti mynginx bash
  • Check a container's logs:
podman logs mynginx
docker logs mynginx
  • Inspect a container's data:
podman inspect mynginx
docker inspect mynginx
  • Check a container's running processes:
podman top mynginx
docker top mynginx
  • Check container's resources consumption:
podman stats mynginx
docker stats mynginx
  • Pause a running container:
podman pause mynginx
docker pause mynginx
  • Unpause a container:
podman unpause mynginx
docker unpause mynginx
  • Stop a container:
podman stop mynginx
docker stop mynginx
  • Start a container:
podman start mynginx
docker start mynginx
  • kill a container:
podman kill mynginx
docker kill mynginx
  • delete a container:
podman delete mynginx
docker delete mynginx

Let’s explore a bit the filesystem

  • Remove all containers:
podman rm -f $(podman ps -aq)
docker rm -f $(docker ps -aq)
  • Get a alpine image:
podman pull alpine
docker pull alpine
  • Check layers of a image:
podman history alpine
docker history alpine
  • Lunch a alpine and attach to it:
podman run --name mytest --ti alpine bash
docker run --name mytest --ti alpine bash

Inside the container (mytest):

echo "Hi" > myfile
rm /etc/localtime

Check the diff

podman diff mytest
docker diff mytest

Create a new image with the changes:

podman commit mytest academy/mytest:r0
docker commit mytest academy/mytest:r0

Check the history of the new image:

podman history academy/mytest:r0
docker history academy/mytest:r0

Export a image:

podman save academy/mytest:ro -o /tmp/image.tar
docker save academy/mytest:ro -o /tmp/image.tar

Image registry:

podman search wordpress
docker search wordpress
podman search wordpress --list-tags

Configuring containers

podman run --name mymaria -d -e MARIADB_ROOT_PASSWORD="pa$$w0rd" -e MARIADB_USER="foo" -e MARIADB_PASSWORD="bar1234" -e MARIADB_DATABASE="academy" docker.io/library/mariadb
docker run --name mymaria -d -e MARIADB_ROOT_PASSWORD="pa$$w0rd" -e MARIADB_USER="foo" -e MARIADB_PASSWORD="bar1234" -e MARIADB_DATABASE="academy" mariadb

Using Networks

podman run --name client --rm -ti docker.io/library/mysql:latest bash
docker run --name client --rm -ti mysql bash

In the console of the container:

mysql -h "mymaria" -u"foo" -p"bar1234" "academy"

You can't access so let's use a networks:

podman network create testnetwork
podman network inspect testnetwork
docker network create testnetwork
docker network inspect testnetwork

Now try to access again:

podman run --name mymaria --hostname mymaria --network testnetwork -d -e MARIADB_ROOT_PASSWORD="pa$$w0rd" -e MARIADB_USER="foo" -e MARIADB_PASSWORD="bar1234" -e MARIADB_DATABASE="academy" mariadb

podman run --name client --network testnetwork -ti --rm docker.io/library/mysql:latest bash
docker run --name mymaria --hostname mymaria --network testnetwork -d -e MARIADB_ROOT_PASSWORD="pa$$w0rd" -e MARIADB_USER="foo" -e MARIADB_PASSWORD="bar1234" -e MARIADB_DATABASE="academy" mariadb

docker run --name client --network testnetwork --rm -ti mysql bash
mysql -h "mymaria" -u"foo" -p"bar1234" "academy"

Port publishing

podman ps -a
podman stop mymaria && docker rm mymaria
podman run --name mymaria -p 3306:3306 --hostname mymaria --network testnetwork -d -e MARIADB_ROOT_PASSWORD="pa$$w0rd" -e MARIADB_USER="foo" -e MARIADB_PASSWORD="bar1234" -e MARIADB_DATABASE="academy" mariadb
docker ps -a
docker stop mymaria && docker rm mymaria
docker run --name mymaria -p 3306:3306 --hostname mymaria --network testnetwork -d -e MARIADB_ROOT_PASSWORD="pa$$w0rd" -e MARIADB_USER="foo" -e MARIADB_PASSWORD="bar1234" -e MARIADB_DATABASE="academy" mariadb

Working with volumes

podman volume create myvol
podman volume inspect myvol
podman run --name cont1 -v myvol:/mnt/volume -ti alpine
podman run --name cont2 -v myvol:/mnt/volume -ti alpine
docker volume create myvol
docker volume inspect myvol
docker run --name cont1 -v myvol:/mnt/volume -ti alpine
docker run --name cont2 -v myvol:/mnt/volume -ti alpine

MariaDB with persistence

podman stop $(podman ps -aq) && podman rm $(podman ps -aq)
docker stop $(docker ps -aq) && docker rm $(docker ps -aq)

Create a new volume

podman volume create mariadb-data
docker volume create mariadb-data

Deploy a new container with the volume

podman run -d -p 3306:3306 --name mymaria \
  --hostname mymaria \
  --network testnetwork \
  -e MARIADB_ROOT_PASSWORD="pa$$w0rd" \
  -e MARIADB_USER="foo" \
  -e MARIADB_PASSWORD="bar123" \
  -e MARIADB_DATABASE="academy" \
  -v mariadb_data:/var/lib/mysql mariadb
docker run -d -p 3306:3306 --name mymaria \
  --hostname mymaria \
  --network testnetwork \
  -e MARIADB_ROOT_PASSWORD="pa$$w0rd" \
  -e MARIADB_USER="foo" \
  -e MARIADB_PASSWORD="bar123" \
  -e MARIADB_DATABASE="academy" \
  -v mariadb_data:/var/lib/mysql mariadb

You can specify a path in your host:

podman run -d -p 3306:3306 --name maria2 \
  --hostname mymaria \
  --network testnetwork \
  -e MARIADB_ROOT_PASSWORD="pa$$w0rd" \
  -e MARIADB_USER="foo" \
  -e MARIADB_PASSWORD="bar1234" \
  -e MARIADB_DATABASE="academy" \
  -v /tmp/mypath:/var/lib/mysql mariadb
docker run -d -p 3306:3306 --name maria2 \
  --hostname mymaria \
  --network testnetwork \
  -e MARIADB_ROOT_PASSWORD="pa$$w0rd" \
  -e MARIADB_USER="foo" \
  -e MARIADB_PASSWORD="bar1234" \
  -e MARIADB_DATABASE="academy" \
  -v /tmp/mypath:/var/lib/mysql mariadb

Dockerfile

podman build -t academy/test:latest .
podman run -d --name test  -p 8080:80 academy/test:latest
docker build -t academy/test:latest .
docker run -d --name test  -p 8080:80 academy/test:latest

Tips for not running out of space

podman container prune
podman image prune
podman volume prune
podman system prune
docker container prune
docker image prune
docker volume prune
docker system prune

Docker Compose

docker run -d --name mymongo mongo
version: '3'
services:
  mongodb:
    image: mongo
    container_name: mymongo
docker compose up -d
docker compose down
docker compose -f docker-compose-mariadb.yaml up -d

Testing docker-compose:

mariadb -h "mariadb" -u"foo" -p"bar1234" "academy"

Some docker compose commands

docker compose ps
docker compose stop client
docker compose run client bash
docker compose run --no-deps client bash
docker compose logs
docker compose down --volumes

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published