_________________________________________________________________
_________________________________________________________________
Running Docker on Linux.
_________________________________________________________________
--1. RedHat Linux
https://docs.docker.com/engine/install/rhel/
Others: CentOS, Debian, Fedora, Ubuntu
Install | Docker Docs
_________________________________________________________________
--2. Install docker RedHat Linux
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
--uninstall docker
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
Error response from daemon: toomanyrequests:
You have reached your unauthenticated pull rate limit.
https://www.docker.com/increase-rate-limit
Solution:
docker login
You must create a docker account at https://docker.com > "Sign in" > Don't have an account "Sign Up".
_________________________________________________________________
--3. Step-by-Step: Grant Docker Access to a Non-Root User
1. Ensure Docker is installed and running
sudo systemctl status docker
2. Create the docker group (if it doesn't exist)
sudo groupadd docker
grep docker /etc/group
getent group | grep docker
getent group docker
cat /etc/group | grep docker
This step is usually not needed if Docker is already installed.
3. Add your user to the docker group
sudo usermod -aG docker your_username
Replace your_username with the actual username.
sudo usermod -aG docker dockerauto
# userdel 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
docker --version
ssh user@linux-host-ip
docker -H ssh://user@linux-host-ip info
docker context create my-linux-docker \
--docker "host=ssh://user@linux-host-ip"
docker context use my-linux-docker
docker info
docker -H "ssh://user@linux-host-ip" --ssh-option IdentityFile=~/.ssh/id_rsa info
ssh-keygen -t rsa -b 4096 -f ~/.ssh/my_custom_key
ssh-copy-id -i ~/.ssh/my_custom_key.pub user@linux-host-ip
cat ~/.ssh/my_custom_key.pub | ssh user@linux-host-ip "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
ssh -i ~/.ssh/my_custom_key user@linux-host-ip
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
ssh-add $env:USERPROFILE\.ssh\id_rsa
ssh-add -l
docker --context default -H "ssh://user@linux-host-ip" \
--ssh-option IdentityFile=~/.ssh/my_custom_key info
docker context create my-linux-docker \
--docker "host=ssh://user@linux-host-ip" \
--description "Remote Docker with custom SSH key"
export DOCKER_SSH_IDENTITYFILE=~/.ssh/my_custom_key
docker context use my-linux-docker
docker linux engine server - PS026300
docker linux user name: dockerauto
!!! dockerauto user is a member of the docker group to be able to run the docker command !!!
docker linux user pwd: docker.auto
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
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
--If ssh-copy-id is not available, you can manually append the key:
cat c:\temp\ssh_key\PS026065_ssh_key.pub | ssh ssh://dockerauto@PS026300 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
su - dockerauto
pwd
ls -la $HOME/.ssh
cat $HOME/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh
powershell:
--Test SSH with the Custom Key
ssh -i c:\temp\ssh_key\PS026065_ssh_key dockerauto@PS026300
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
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
--(it might not have copied check, then copy manually if necessary)
ssh-add $env:USERPROFILE\.ssh\id_rsa\PS026065_ssh_key
ssh-add -l
ssh-add -d $env:USERPROFILE\.ssh\id_rsa\PS026065_ssh_key
--remove all keys
ssh-add -D
ssh -i c:\temp\ssh_key\PS026065_ssh_key dockerauto@PS026300
ssh dockerauto@PS026300
--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
docker context rm linux-docker-PS026300
docker context create linux-docker-PS026300 --docker "host=ssh://dockerauto@PS026300" --description "Linux Docker Agent PS026300 with custom SSH key"
--export DOCKER_SSH_IDENTITYFILE=c:\temp\ssh_key\PS026065_ssh_key (NO NEED ON WINDOWS!!!)
docker context use linux-docker-PS026300
docker ps -a ( !!! it will list the containers in the docker linux agent !!! )
_________________________________________________________________
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.