Select to view content in your preferred language

Linux Docker Installation

63
0
Friday
ShareUser
Esri Community Manager
0 0 63

_________________________________________________________________

docker-logo-blue.png

 


_________________________________________________________________

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

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:
 
Extract the ZIP file to a folder (e.g., C:\docker-cli).
 
Add the folder to your system PATH:
 
Open System Properties > Environment Variables
Under 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. Prerequisites
Docker installed on Windows (Docker Desktop or Docker CLI)
Docker Engine running on the Linux host
SSH access from Windows to the Linux host
Your SSH key added to the Linux host (or password access enabled)
 
2. Enable SSH Access to Docker on Linux
Ensure 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 Context
Option A: One-time command
docker -H ssh://user@linux-host-ip info
Option B: Create a Docker context
This 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 Keys
If you used a passphrase, you can use ssh-agent to avoid entering it every time:
 
Install SSH Agent via PowerShell
1. Open PowerShell as Administrator
2. 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 Key
Option A: One-time command
docker --context default -H "ssh://user@linux-host-ip" \
  --ssh-option IdentityFile=~/.ssh/my_custom_key info
Option B: Create a Docker context with the custom key
docker context create my-linux-docker \
  --docker "host=ssh://user@linux-host-ip" \
  --description "Remote Docker with custom SSH key"
Then set the environment variable to use the key:
export DOCKER_SSH_IDENTITYFILE=~/.ssh/my_custom_key
docker context use my-linux-docker
_________________________________________________________________
--8. Step by Step Example:
 
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
 
Windows Machine:
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 Machine:
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"
Linux Machine:
su - dockerauto
pwd
ls -la $HOME/.ssh
cat $HOME/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh
Windows Machine:
powershell:  
--Test SSH with the Custom Key
ssh -i c:\temp\ssh_key\PS026065_ssh_key dockerauto@PS026300
--open new powershell windows as 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
--open new powershell windows as no administrator
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
--remove the key
ssh-add -d $env:USERPROFILE\.ssh\id_rsa\PS026065_ssh_key
--remove all keys
ssh-add -D
--Test SSH with the Custom Key
ssh -i c:\temp\ssh_key\PS026065_ssh_key dockerauto@PS026300
ssh dockerauto@PS026300
Windows Machine:
powershell:  
--Option A: One-time command
--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: Create a Docker context with the custom key
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"
--Then set the environment variable to use the 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 !!! )

_________________________________________________________________

Tags (2)
Labels