Docker with Centos 8 - shaysalomon12/Data-Engineer GitHub Wiki

Creating Container

  1. Verify Docker Desktop is running. Open PowerShell. Pull latest Centos 8 docker image:
  • Create the virtual network driver (PowerShell):
docker network create --driver bridge some-network
  • Pull and start Centos 8 image
docker run -d -v /sys/fs/cgroup:/sys/fs/cgroup:ro -h myCentos8 --name myCentos8 --network some-network -p 22:22 -p 3306:3306 --memory 1g --privileged=true -it centos /usr/sbin/init

This is a persistant image. Any change made inside the Docker will be saved.

  1. Show running containers (PowerShell):
docker ps

Output

CONTAINER ID   IMAGE     COMMAND            CREATED        STATUS          PORTS                NAMES
46fa9600b9c1   centos    "/usr/sbin/init"   25 hours ago   Up 33 minutes   0.0.0.0:22->22/tcp   **myCentos8**
  1. Show networks (PowerShell):
docker network ls

Output

NETWORK ID     NAME           DRIVER    SCOPE
beaac8852cb9   bridge         bridge    local
c2151a6a2dcd   host           host      local
67183e41ce39   none           null      local
e631a347fcd6   some-network   bridge    local
  1. Show online statistics for containers (PowerShell):
docker stats

Output

CONTAINER ID   NAME        CPU %     MEM USAGE / LIMIT   MEM %     NET I/O           BLOCK I/O   PIDS
46fa9600b9c1   myCentos8   0.00%     29.51MiB / 1GiB     2.88%     38.5kB / 36.4kB   0B / 0B     12
  1. Connect to Linux bash (PowerShell):
docker exec -it myCentos8 bash
  1. Enable repository access (bash):
cd /etc/yum.repos.d/
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
  1. Install ssh (bash):
yum install openssh-clients openssh-server passwd
  1. Start ssh server (bash):
systemctl start sshd
systemctl enable sshd
  1. Set the root password (bash)
passwd
  1. Connect to Linux from MobaXterm (or Putty):
ssh [email protected] -p 22

Manage Dockers from Docekr Desktop GUI:

  • List Images: image
  • List Containers: image
  • **Terminal for a Container: ** image
  • Log for Container: image

Reclaiming disk space

  • Monitor the size of file ext4.vhdx in directory C:\Users\ShaySalomon\AppData\Local\Docker\wsl\data

  • You can find ext4.vhdx location from Docker Desktop GUI: Settings -> Resources -> Advanced, under "Disk image location"

  • If this file is too big and you wish to re-initialize it use the following steps.

  • If you don't mind completely wiping out your docker data and re-creating it all, then you can unregister the docker-desktop-data wsl2 distro.

  • This will remove ALL containers, ALL volumes, ALL configuration, ALL downloaded images and so on.

  • Stop Docker Desktop (Poweshell)

wsl --shutdown
  • Unregister ((Poweshell)
wsl --unregister docker-desktop-data
  • When you start Docker Desktop, a new ext4.vhdx file will be created with a size of 1.5gb.