By default, the docker command can only be run the root user or by a user in the docker group, which is automatically created during Docker’s installation process. If you attempt to run the docker command without prefixing it with sudo or without being in the docker group, you’ll get an output like this:

Outputdocker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?.
See 'docker run --help'.
If you want to avoid typing sudo whenever you run the docker command, add your username to the docker group:

sudo usermod -aG docker ${USER}
If you need to add a user to the docker group that you’re not logged in as, declare that username explicitly using:

sudo usermod -aG docker username
Next, set the correct permissions to make sure the docker-compose command is executable:

sudo chmod +x /usr/local/bin/docker-compose
Confirm that your user is now added to the docker group by typing:

groups
To apply the new group membership, log out of the server and back in, or type the following:

su - ${USER}

I installed docker on a new ubuntu 18.04 server and verified how it works the firewalld when running docker in simple way.
The image is httpd which I used.


# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04 LTS
Release:        18.04
Codename:       bionic

# uname -a 
Linux my_hostname 4.15.0-20-generic #21-Ubuntu SMP Tue Apr 24 06:16:15 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

$ sudo docker image list
REPOSITORY     TAG                 IMAGE ID            CREATED             SIZE
httpd          latest              fb2f3851a971        2 weeks ago         178MB
$ sudo docker run -d -i -t -p 80:80 httpd
$ sudo docker ps -a
CONTAINER ID   IMAGE      COMMAND              CREATED             STATUS             PORTS                NAMES
43b398cfa5b9   httpd      httpd-foreground"   31 minutes ago       Up 31 minutes       0.0.0.0:80->80/tcp   loving_northcutt
# ss -tlp
State      Recv-Q         Send-Q         Local Address:Port    Peer Address:Port
LISTEN      0              128                 *:http                 *:*          users:(("docker-proxy",pid=2101,fd=4))
# firewall-cmd --list-all
public
  target: default
  interfaces:
  sources:
  services: ssh dhcpv6-client
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:    

In this network have defined data like this:


ubuntu@pro_staging:~> sudo docker network ls
NETWORK ID          NAME                 DRIVER              SCOPE
fb1861a4afc0        projecName_default   bridge              local
e60b761f9aa9        bridge               bridge              local
0ab8ff5w5f2d        host                 host                local
a4e689dc9dcb        none                 null                local
ubuntu@pro_staging:~> sudo docker inspect projecName_default
[
    {
        "Name": "projecName_default",
        "Id": "fb1861a4ac4059f6abea25b49c331390d651fdsdde24e15a848507723c2e4cd4f",
        "Created": "2018-11-02T11:15:37.136315048Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.20.0.0/16",
                    "Gateway": "172.20.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "87855a403d18df21910d6fd6d0132328d09a954800200e46ad35fa325fb42897f": {
                "Name": "projecName_default_containr1",
                "EndpointID": "a55d85fb759d997957fdd15eddba28e1598176d7c5bdb9e2d42fd1967f7f763b",
                "MacAddress": "02:42:ac:14:00:03",
                "IPv4Address": "172.20.0.3/16",
                "IPv6Address": ""
            },
            "9b0d45d8310e9877de147b89dd74c7dfb2d55a1660c7ab664f3e831d100eee0f": {
                "Name": "projecName_default_containr_2",
                "EndpointID": "68ba68e2c4bb3a7a8861b1fa2d43edecbfc0d29586c8169361bb47e94c37d460",
                "MacAddress": "02:42:ac:14:00:04",
                "IPv4Address": "172.20.0.4/16",
                "IPv6Address": ""
            },
            "edf3bf11199dba6b7ada6105773341baca4790ff713d40988ffbe54cd73a638d": {
                "Name": "projecName_default_containr_3",
                "EndpointID": "62d17e5b7f1909d60aa4c79fccb276f5a50f84d79b9da8d6f6bf5c7f54cb313f",
                "MacAddress": "02:42:ac:14:00:02",
                "IPv4Address": "172.20.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

Recommend

How To Install and Use Docker on Ubuntu 20.04 Step 1 — Installing Docker

Использование Visual Studio Code для удаленной разработки с помощью плагина Remote-SSH Шаг 3 — Выполнение кода на удаленном сервере

Использование Visual Studio Code для удаленной разработки с помощью плагина Remote-SSH Шаг 2 — Настройка плагина Remote-SSH и подключение к серверу

Built-in Python 3 Functions for Working with Numbers Prerequisites Still looking for an answer?

Built-in Python 3 Functions for Working with Numbers Calculating a Sum

Built-in Python 3 Functions for Working with Numbers Rounding Numbers

Built-in Python 3 Functions for Working with Numbers Power

Built-in Python 3 Functions for Working with Numbers Absolute Value Finding the Quotient and Remainder in One Function

Built-in Python 3 Functions for Working with Numbers Absolute Value

Cómo indexar, dividir y manipular cadenas en JavaScript Búsqueda y sustitución de valores de cadenas

Cómo indexar, dividir y manipular cadenas en JavaScript Recorte de espacios en blanco

Cómo indexar, dividir y manipular cadenas en JavaScript División de cadenas

Cómo indexar, dividir y manipular cadenas en JavaScript Conversión a mayúsculas o minúsculas

Cómo indexar, dividir y manipular cadenas en JavaScript Búsqueda de la longitud de una cadena

Cómo indexar, dividir y manipular cadenas en JavaScript Acceso a los caracteres

Cómo indexar, dividir y manipular cadenas en JavaScript Las primitivas de cadena y los objetos String

How To Set Up Zoho Mail with a Custom Domain Managed by DigitalOcean DNS Conclusion Want to learn more? Join the DigitalOcean Community! Still looking for an answer?

Cómo instalar y proteger Redis en Ubuntu 18.04 Paso 5 - Renombrar comandos peligrosos

Cómo instalar y proteger Redis en Ubuntu 18.04 Paso 4 - Configurar un contraseña de Redis

Cómo instalar y proteger Redis en Ubuntu 18.04 Paso 3: Vinculación a localhost

Cómo instalar y proteger Redis en Ubuntu 18.04 Paso 2: Pruebas en Redis

Cómo instalar y proteger Redis en Ubuntu 18.04 Paso 1: Instalación y configuración de Redis

Securing Communications in a Three-tier Rails Application Using SSH Tunnels Step 8 — Configuring Nginx