_________________________________________________________________
a0
_________________________________________________________________
Docker unter Linux ausführen.
_________________________________________________________________
--1. RedHat Linux
https://docs.docker.com/engine/install/rhel/
Andere: CentOS, Debian, Fedora, Ubuntu
Installieren | Docker Docs
_________________________________________________________________
--2. Docker auf RedHat Linux installieren
dnf remove docker
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine \
podman \
runc
sudo dnf -y install dnf-plugins-core
sudo dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo
sudo dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin \
docker-compose-plugin
docker login
sudo systemctl enable --now docker
sudo systemctl start docker
sudo systemctl stop docker
sudo systemctl status docker
sudo systemctl disable docker
sudo docker run hello-world
--Docker deinstallieren
sudo dnf remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin \
docker-compose-plugin docker-ce-rootless-extras
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
_________________________________________________________________
sudo systemctl enable --now docker
Fehlerantwort vom Daemon: toomanyrequests:
Sie haben Ihr nicht authentifiziertes Pull-Limit erreicht.
https://www.docker.com/increase-rate-limit
--Lösung:
docker login
Sie müssen ein Docker-Konto erstellen unter https://docker.coma0> "Anmelden" > Kein Konto? "Registrieren".
_________________________________________________________________
--3. Schritt-für-Schritt: Docker-Zugriff für einen Nicht-Root-Benutzer gewähren
1. Sicherstellen, dass Docker installiert und läuft
sudo systemctl status docker
2. Die Docker-Gruppe erstellen (falls sie nicht existiert)
sudo groupadd docker
grep docker /etc/group
getent group | grep docker
getent group docker
cat /etc/group | grep docker
Dieser Schritt ist normalerweise nicht erforderlich, wenn Docker bereits installiert ist.
3. Ihren Benutzer zur Docker-Gruppe hinzufügen
sudo usermod -aG docker your_username
Ersetzen Sie your_username durch den tatsächlichen Benutzernamen.
sudo usermod -aG docker dockerauto
# useradd -g docker dockerauto
# id -a dockerauto
passwd dockerauto
docker.4Automation@Harness&Test
4. Log out and log back in
This step is important to apply the new group membership. You can also use:
newgrp docker
to apply the group change without logging out.
5. Test Docker access
docker run hello-world
_________________________________________________________________
--4. Docker Linux Directory
https://docs.docker.com/engine/daemon/
Yes, in Docker, it is possible to choose the Linux directory where container data is stored, but it requires configuring the Docker storage directory.
By default, Docker stores all its data (images, containers, volumes, etc.) in:
/var/lib/docker
To change this directory:
Modify the Docker Daemon Configuration
Create or edit the Docker daemon config file:
sudo nano /etc/docker/daemon.json
Add or modify the data-root setting:
{"data-root": "/your/custom/docker-directory"}
Stop Docker:
sudo systemctl stop docker
Move existing data (optional but recommended if you want to preserve current containers/images):
sudo rsync -aP /var/lib/docker/ /your/custom/docker-directory
Start Docker:
sudo systemctl start docker
Verify:
docker info | grep "Docker Root Dir"
Example:
root@PS026300 dockerhome# cat /etc/docker/daemon.json
{
"data-root": "/dockerhome/dockerdata"
}
root@PS026300 dockerhome#
systemctl stop docker
mv /var/lib/docker/* /dockerhome/dockerdata/.
ls -la /var/lib/docker
ls -la /dockerhome/dockerdata
systemctl start docker
systemctl status docker
docker info | grep "Docker Root Dir"
_________________________________________________________________
--5. RedHat Linux - How to Create a Linear Volume
# fdisk -l /dev/sdc
Disk /dev/sdc: 214.7 GB, 214748364800 bytes, 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xe890f319.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-419430399, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-419430399, default 419430399):
Using default value 419430399
Partition 1 of type Linux and of size 200 GiB is set
Command (m for help): p
Disk /dev/sdc: 214.7 GB, 214748364800 bytes, 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xe890f319
Device Boot Start End Blocks Id System
/dev/sdc1 2048 419430399 209714176 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
# fdisk -l /dev/sdc
Disk /dev/sdc: 214.7 GB, 214748364800 bytes, 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xe890f319
Device Boot Start End Blocks Id System
/dev/sdc1 2048 419430399 209714176 83 Linux
#
--Volume group
# vgcreate vgdockerhome /dev/sdc1
# vgscan
# vgdisplay vgdockerhome
--Logical Volume
# lvcreate -l 51199 vgdockerhome -n lvdockerhome
# lvdisplay -v /dev/vgdockerhome/lvdockerhome
--Format the volume
--# mkfs.ext3 /dev/vgdockerhome/lvdockerhome
--# mkfs.ext4 /dev/vgdockerhome/lvdockerhome --rhel_7,8,9
# mkfs.xfs /dev/vgdockerhome/lvdockerhome --rhel_7,8,9
--Mount
# mkdir /pghome
--# mount -t ext3 -o noatime /dev/vgdockerhome/lvdockerhome /dockerhome
--# mount -t ext4 -o noatime /dev/vgdockerhome/lvdockerhome /dockerhome --rhel_7,8,9
# mount -t xfs -o noatime /dev/vgdockerhome/lvdockerhome /dockerhome --rhel_7,8,9
--Persist the mount
vi /etc/fstab
#mount logical volume
#/dev/vgdockerhome/lvdockerhome /dockerhome ext3 defaults,noatime 1 1
#/dev/vgdockerhome/lvdockerhome /dockerhome ext4 defaults,noatime 1 1 <== --rhel_7,8,9
/dev/vgdockerhome/lvdockerhome /dockerhome xfs defaults,noatime 1 1 <== --rhel_8,9
:wq!
--How to remove volumes
--remove logical volume
# lvremove /dev/vgdockerhome/lvdockerhome
--remove volume group
# vgremove vgdockerhome
--More info at:
Configuring and managing logical volumes | Red Hat Enterprise Linux | 9 | Red Hat Documentation
_________________________________________________________________
--6. Docker CLI on Windows
Install Docker CLI Only (Without Docker Engine) If you only need the CLI to connect to a remote Docker host: Step-by-Step: Download Docker CLI binaries Visit:https://download.docker.com/win/static/stable/x86_64/ Extract the ZIP file to a folder (e.g., C:\docker-cli). Add the folder to your system PATH: Open System Properties > Environment VariablesUnder System variables, find Path, click Edit, and add the path to your Docker CLI folder. Open a new terminal and test:
docker --version
This method is useful if you're using Docker with remote hosts (via SSH or TLS) and don’t need Docker Engine running locally.
_________________________________________________________________
--7. To use the Docker CLI on Windows to control a Docker Engine running on a remote Linux host over SSH, follow these steps: 1. PrerequisitesDocker installed on Windows (Docker Desktop or Docker CLI)Docker Engine running on the Linux hostSSH access from Windows to the Linux hostYour SSH key added to the Linux host (or password access enabled) 2. Enable SSH Access to Docker on LinuxEnsure the Linux host has Docker running and SSH access enabled. You can test SSH access from Windows (PowerShell or Git Bash):
ssh user@linux-host-ip
3. Use Docker CLI with SSH ContextOption A: One-time command
docker -H ssh://user@linux-host-ip info
Option B: Create a Docker contextThis is more convenient for repeated use:
docker context create my-linux-docker \
--docker "host=ssh://user@linux-host-ip"
Then switch to that context:
docker context use my-linux-docker
Now, any docker command you run will be executed on the remote Linux host. 4. Verify
docker info
5. Optional: Use SSH Key
docker -H "ssh://user@linux-host-ip" --ssh-option IdentityFile=~/.ssh/id_rsa info
To set up a custom SSH key for Docker CLI to connect to a remote Docker Engine over SSH, follow these steps: 1. Generate a Custom SSH Key (if you don’t have one yet)On your Windows machine (using PowerShell or Git Bash):
ssh-keygen -t rsa -b 4096 -f ~/.ssh/my_custom_key
This creates:~/.ssh/my_custom_key (private key)~/.ssh/my_custom_key.pub (public key) 2. Copy the Public Key to the Linux Host
ssh-copy-id -i ~/.ssh/my_custom_key.pub user@linux-host-ip
If ssh-copy-id is not available, you can manually append the key:
cat ~/.ssh/my_custom_key.pub | ssh user@linux-host-ip "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
3. Test SSH with the Custom Key
ssh -i ~/.ssh/my_custom_key user@linux-host-ip
If it logs in without a password, you're good to go. Optional: Use SSH Agent for Passphrase-Protected KeysIf you used a passphrase, you can use ssh-agent to avoid entering it every time: Install SSH Agent via PowerShell1. Open PowerShell as Administrator2. Check if OpenSSH Client is Installed:
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Client*'
3. If it shows State : NotPresent, install it:
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
4. Enable and Start the SSH Agent Service:
Set-Service -Name ssh-agent -StartupType Automatic
Start-Service ssh-agent
--open new powershell windows not as administrator
ssh-add $env:USERPROFILE\.ssh\id_rsa
ssh-add -l
--do this in powershell in the windows machine. 4. Use Docker CLI with the Custom SSH KeyOption A: Einmaliger Befehl
docker --context default -H "ssh://user@linux-host-ip" \
--ssh-option IdentityFile=~/.ssh/my_custom_key info
Option B: Erstellen Sie einen Docker-Kontext mit dem benutzerdefinierten Schlüssel
docker context create my-linux-docker \
--docker "host=ssh://user@linux-host-ip" \
--description "Remote Docker mit benutzerdefiniertem SSH-Schlüssel"
Dann setzen Sie die Umgebungsvariable, um den Schlüssel zu verwenden:
export DOCKER_SSH_IDENTITYFILE=~/.ssh/my_custom_key
docker context use my-linux-docker
_________________________________________________________________
--8. Schritt-für-Schritt-Beispiel:
docker linux engine server - PS026300
docker linux Benutzername: dockerauto
!!! Der Benutzer dockerauto ist Mitglied der docker-Gruppe, um den docker-Befehl ausführen zu können !!!
docker linux Benutzer-Passwort: docker.auto
Windows-Rechner:
powershell: ssh dockerauto@PS02630
docker -H ssh://dockerauto@PS026300 info
docker context ls
docker context rm linux-docker-PS026300
docker context create linux-docker-PS026300 --docker "host=ssh://dockerauto@PS026300"
docker context use linux-docker-PS026300
docker context show
docker ps -a
docker context list
Windows-Rechner:
powershell:
cd c:\temp\ssh_key
ssh-keygen -t rsa -b 4096 -f c:\temp\ssh_key\PS026065_ssh_key
Passphrase: docker.auto
--ssh-copy-id -i c:\temp\ssh_key\PS026065_ssh_key.pub dockerauto@PS026300
--Falls ssh-copy-id nicht verfügbar ist, können Sie den Schlüssel manuell anhängen:
cat c:\temp\ssh_key\PS026065_ssh_key.pub | ssh ssh://dockerauto@PS026300 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Linux-Rechner:
su - dockerauto
pwd
ls -la $HOME/.ssh
cat $HOME/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh
Windows-Rechner:
powershell:
--SSH mit dem benutzerdefinierten Schlüssel testen
ssh -i c:\temp\ssh_key\PS026065_ssh_key dockerauto@PS026300
--Öffnen Sie neue Powershell-Fenster als Administrator
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Client*'
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
Set-Service -Name ssh-agent -StartupType Automatic
Start-Service ssh-agent
--Öffnen Sie neue Powershell-Fenster ohne Administratorrechte
mkdir C:\Users\marc3932\.ssh\id_rsa
New-Item -Path "C:\Users\marc3932\.ssh\id_rsa" -ItemType Directory
Copy-Item -Path "c:\temp\ssh_key\PS026065_ssh_key\*" -Destination "C:\Users\marc3932\.ssh\id_rsa" -Recurse
--(Es könnte sein, dass es nicht kopiert wurde, überprüfen Sie dies und kopieren Sie ggf. manuell)
ssh-add $env:USERPROFILE\.ssh\id_rsa\PS026065_ssh_key
ssh-add -l
--Entfernen des Schlüssels
ssh-add -d $env:USERPROFILE\.ssh\id_rsa\PS026065_ssh_key
--Alle Schlüssel entfernen
ssh-add -D
--SSH mit dem benutzerdefinierten Schlüssel testen
ssh -i c:\temp\ssh_key\PS026065_ssh_key dockerauto@PS026300
ssh dockerauto@PS026300
Windows-Rechner:powershell:
--Option A: Einmaliger Befehl
--docker --context default -H "ssh://dockerauto@PS026300" --ssh-option IdentityFile=c:\temp\ssh_key\PS026065_ssh_key
--docker -H "ssh://dockerauto@PS026300" --ssh-option IdentityFile=c:\temp\ssh_key\PS026065_ssh_key
docker -H "ssh://dockerauto@PS026300" info
--Option B: Erstellen Sie einen Docker-Kontext mit dem benutzerdefinierten Schlüssel
docker context rm linux-docker-PS026300
docker context create linux-docker-PS026300 --docker "host=ssh://dockerauto@PS026300" --description "Linux Docker Agent PS026300 mit benutzerdefiniertem SSH-Schlüssel"
--Dann setzen Sie die Umgebungsvariable, um den Schlüssel zu verwenden:
--export DOCKER_SSH_IDENTITYFILE=c:\temp\ssh_key\PS026065_ssh_key (NICHT NÖTIG UNTER WINDOWS!!!)
docker context use linux-docker-PS026300
docker ps -a ( !!! es listet die Container im Docker Linux Agent auf !!! )
_________________________________________________________________