Docker with Centos 8 - shaysalomon12/Data-Engineer GitHub Wiki
Creating Container
- 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.
- 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**
- 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
- 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
- Connect to Linux bash (PowerShell):
docker exec -it myCentos8 bash
- 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-*
- Install ssh (bash):
yum install openssh-clients openssh-server passwd
- Start ssh server (bash):
systemctl start sshd
systemctl enable sshd
- Set the root password (bash)
passwd
- Connect to Linux from MobaXterm (or Putty):
ssh [email protected] -p 22
Manage Dockers from Docekr Desktop GUI:
- List Images:
- List Containers:
- **Terminal for a Container: **
- Log for Container:
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.