How to

Install Docker Community Edition ( DockerCE )

sudo apt remove docker docker-engine docker.io containerd runc ; \
sudo apt install ca-certificates curl gnupg lsb-release ; \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt update ; \ 
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin


sudo groupadd docker ; \
sudo usermod -aG docker $USER ; \
newgrp docker

# Optional
sudo chown "$USER":"$USER" /home/"$USER"/.docker -R ; \
sudo chmod g+rwx "$HOME/.docker" -R


sudo systemctl enable docker.service ; \
sudo systemctl enable containerd.service

sudo gpasswd -a $USER docker

Uninstall Docker

Remove all non-used docker containers

Removing "<none>" images

Show real-time logs from the initialized container

Size of container

Get running containers

Name

JSON

Show online/offline containers

Create temporary containers

Docker Service Providers DNS

Specify DNS servers for Docker

Memory

For instance, let's limit the memory that the container can use to 512 megabytes. To constrain memory, we need to use the m parameter:

We can also set a soft limit called a reservation. It's activated when docker detects low memory on the host machine:

CPU

By default, access to the computing power of the host machine is unlimited. We can set the CPUs limit using the cpus parameter. For example, let's constrain our container to use at most two CPUs:

We can also specify the priority of CPU allocation. The default is 1024, higher numbers are higher priority:

Similar to the memory reservation, CPU shares play the main role when computing power is scarce and needs to be divided between competing processes.

Setting Memory Limit With the docker-compose File

We can achieve similar results using docker-composearrow-up-right files. Mind that the format and possibilities will vary between versions of docker-compose.

Versions 3 and Newer With docker swarm

Let's give the Nginx service limit of half of CPU and 512 megabytes of memory, and reservation of a quarter of CPU and 128 megabytes of memory. We need to create “deploy” and then “resources” segments in our service configuration:

To take advantage of the deploy segment in a docker-compose file, we need to use the docker stackarrow-up-right command. To deploy a stack to the swarm, we run the deploy command:

Version 2 With docker-compose

In older versions of docker-compose, we can put resource limits on the same level as the service's main properties. They also have slightly different naming:

To create configured containers, we need to run the docker-compose command:

Verifying Resources Usage

After we set the limits, we can verify them using the docker stats command:

MACOS

Set Bridge IP (docker bip)

If the Docker Engine default bridge network is conflicting with your internal network hosts access, you can change the default Docker subnet by following these steps:

  1. First, you need to delete your old containers

  2. Next, change the subnet IP inside "/etc/docker/daemon.json", by using this command:

  3. Type in the Netmask IP. With the following structure. Please keep in mind that the IP used here is an example:

  4. Restart the Docker Daemon by using this command:

  5. Create a new VSS container and postgres with the following command:

And that’s it!

Docker unable to access from VPN

Linux

Using Docker Compose + OpenVPN

Set the content below inside your docker-compose file:

Windows

  • Set a "default-address-pool"

  • Set a subnet network inside the docker-compose file

Last updated

Was this helpful?