Category: Docker

  • How to Install Docker on AlmaLinux 9

    How to Install Docker on AlmaLinux 9

    To install Docker on AlmaLinux 9, enable Docker repository

    dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo

    To install docker, run

    dnf install docker-ce

    To start docker on boot, run

    systemctl enable docker

    To start docker

    systemctl start docker

    To verify if docker is working, run

    docker run hello-world

    Install older version of docker

    First, remove the current docker version with the command

    dnf remove docker-ce -y

    To list all available docker versions, run

    dnf list docker-ce --showduplicates | sort -r

    To install an older version of docker, specify the version and –nobest option, for example

    dnf install docker-ce docker-ce-3:25.0.5-1.el9 --nobest

    If you do a “dnf upgrade”, docker-ce package will get upgraded to the new version. To prevent this from happening, you need to use DNF versionlock plugin

    Install DNF versionlock plugin with the command:

    dnf install python3-dnf-plugins-extras-versionlock

    Add docker-ce to versionlock

    dnf versionlock add docker-ce

    To view all packages that are versionlocked, run

    dnf versionlock list

    If you ever want to upgrade the package docker-ce, delete it from versionlock with the command

    dnf versionlock delete docker-ce

    Back to Docker

  • How to install Gearman Job Server in Docker

    How to install Gearman Job Server in Docker

    Gearman is an Open Source job server.

    http://gearman.org/getting-started/

    To install it using docker, first install docker, then run

    docker run --name sok-gearmand --restart=unless-stopped -p 4730:4730 -d dockage/gearmand
    

    German is now available on your system. You can connect using IP 127.0.0.1 port 4730.

    Back to Docker

  • How to run docker with csf firewall

    How to run docker with csf firewall

    When running docker on a server with CSF firewall, you may face network connection error because iptables rules added by docker getting replaced by CSF firewall.

    If your docker installation is exposing service to localhost, which is skipped by CSF firewall by default, you can do the following, which will skip the docker0 interface also, so the connection between docker and localhost won’t be affected by CSF firewall. To expose the service to the public, you can use a reverse proxy like Nginx.

    Edit csf.conf

    vi /etc/csf/csf.conf 
    

    Find

    ETH_DEVICE_SKIP = ""
    

    Replace with

    ETH_DEVICE_SKIP = "docker0"
    

    Restart CSF

    csf -r
    

    Back to CSF, Docker

  • How to Install Docker on Oracle Linux 8

    How to Install Docker on Oracle Linux 8

    Oracle Linux Server 8 does not include docker in the official repository, it provides Podman as an alternative to docker.

    We can install the Docker Community Edition on Oracle Linux Server 8.x from the Docker repository.

    Enable Docker repository

    dnf install -y dnf-utils
    dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
    

    Install Docker Community Edition with command

    dnf install -y docker-ce
    

    Set docker to start on boot

    systemctl enable docker
    

    To start docker

    systemctl start docker
    

    To stop docker

    systemctl stop docker
    

    Back to Docker

  • How to install Docker on CentOS 8

    How to install Docker on CentOS 8

    RHEL replaced Docker on RHEL 8 (CentOS 8) with podman. To install Docker on CentOS, you can do the fallowing steps.

    Install yum-utils

    yum install -y yum-utils
    

    Add Docker repository

    yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    

    Install Docker with

    yum install docker-ce docker-ce-cli containerd.io
    

    Enable docker to start on boot

    systemctl enable docker
    

    Start docker

    systemctl start docker
    

    Check the status of the docker

    systemctl status docker
    

    Back to docker

  • podman

    Podman is a daemonless, open source, Linux native tool designed to make it easy to find, run, build, share and deploy applications using Open Containers Initiative (OCI) Containers and Container Images. It is compatible with docker cli, so you can alias podman to docker.

    To install Podman on Oracle Linux 8, run

    dnf install podman
    

    Once installed, you can search for a container image with the command

    podman search nginx
    

    To run nginx container, use the command

    podman run -d -p 80:80 docker.io/library/nginx
    

    Example

    [root@nginx-proxy ~]# podman run -d -p 80:80 docker.io/library/nginx
    264b06dd3b0a2f2a2823562fd4c5dd3cd7f9a312baf17765df060d4e72e55725
    [root@nginx-proxy ~]#
    
    [root@nginx-proxy ~]# podman ps
    CONTAINER ID  IMAGE                           COMMAND               CREATED             STATUS                 PORTS               NAMES
    264b06dd3b0a  docker.io/library/nginx:latest  nginx -g daemon o...  About a minute ago  Up About a minute ago  0.0.0.0:80->80/tcp  wonderful_heisenberg
    [root@nginx-proxy ~]# podman stop 264b06dd3b0a
    264b06dd3b0a
    [root@nginx-proxy ~]# podman rm 264b06dd3b0a
    264b06dd3b0a2f2a2823562fd4c5dd3cd7f9a312baf17765df060d4e72e55725
    [root@nginx-proxy ~]# 
  • How to check if running inside Docker?

    To check if you are inside a docker container, run the command

    cat /proc/1/cgroup | grep --color  docker
    

    If you get some result with docker in it, you are inside a docker container.

    Example

    identify docker container

    See Docker

  • Create Dockerfile From Image

    Create Dockerfile From Image

    If you have a docker image and don’t have the Dockerfile used to create the image, dfimage can help you re-create Dockerfile. To find information about an image, you can use the command “docker history IMAGE_ID”. History command will show all actions taken on the image, including the commands used. You can use this information to reverse engineer and create the missing Dockerfile.

    There is a tool for automating this task, it is called dfimage. It is available on the docker hub.

    https://hub.docker.com/r/laniksj/dfimage

    To use it, run

    docker pull laniksj/dfimage
    docker run -v /var/run/docker.sock:/var/run/docker.sock  --rm laniksj/dfimage IMAGE_ID
    

    In the above command, replace IMAGE_ID with image ID of the docker image for which you need Dockerfile created.

    Example

    docker run -v /var/run/docker.sock:/var/run/docker.sock  --rm laniksj/dfimage  4a7a1f401734
    

    See Docker

  • Build a docker container with Apache

    To create a docker container with Apache, create a Dockerfile

    mkdir my-app
    cd my-app
    vi Dockerfile
    

    Paste following content into the Dockerfile

    from ubuntu:20.04
    
    ARG DEBIAN_FRONTEND=noninteractive
    
    RUN apt-get update && apt-get install -y apache2
    
    RUN echo 'Hello World!' > /var/www/html/index.html
    
    RUN echo '. /etc/apache2/envvars' > /root/run_apache.sh && \
     echo 'mkdir -p /var/run/apache2' >> /root/run_apache.sh && \
     echo 'mkdir -p /var/lock/apache2' >> /root/run_apache.sh && \ 
     echo '/usr/sbin/apache2 -D FOREGROUND' >> /root/run_apache.sh && \ 
     chmod 755 /root/run_apache.sh
    
    EXPOSE 80
    
    CMD /root/run_apache.sh
    

    Now build an image with command

    docker build -t sevrerok/okapache:1.0 .
    

    Once image is build, you can see it using docker images command

    [root@instance-20210426-0136 my-app]# docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    sevrerok/okapache   1.2                 c3832b03b548        8 minutes ago       214MB
    sevrerok/okapache   1.1                 d1a86f0eb69a        37 minutes ago      214MB
    ubuntu              20.04               7e0aa2d69a15        2 days ago          72.7MB
    sevrerok/okapache   1.0                 7e0aa2d69a15        2 days ago          72.7MB
    [root@instance-20210426-0136 my-app]# 
    

    To start a container with the image, run

    docker container run -d -p 80:80 sevrerok/okapache:1.0
    

    See docker build

  • Install Odoo using Docker

    Odoo is an open source ERP and CRM software written in python. To install Odoo using docker, first install docker using

    wget -qO- https://get.docker.com/ | sh
    

    Odoo use PostgreSQL server to store database. Lets create a postgres docker container.

    docker run -d -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=your-password-here -e POSTGRES_DB=postgres --name odoo-db postgres:10
    

    In above command, replace your-password-here with a secure password.

    Create a Odoo container with

    docker run -d -p 127.0.0.1:8069:8069 -p 127.0.0.1:8072:8072 --name odoo --link odoo-db:db -t odoo
    

    If container did not start on boot, enable start on boot with

    docker update --restart=unless-stopped CONTAINER_ID
    

    You can find CONTAINER_ID with docker ps or docker ps -a command.

    Next we need to configure a domain to be used with Odoo. For this, we use nginx web server as reverse proxy. Lets install nginx web server with command

    apt install nginx
    

    Install LetsEncrypt with

    wget https://raw.githubusercontent.com/serverok/server-setup/master/install/letsencrypt.sh
    bash ./letsencrypt.sh
    

    Before getting SSL, we need to configure Nginx web server with a simple config file for our domain.

    vi /etc/nginx/sites-enabled/odoo.conf
    

    Add

    server {
        listen 80;
        server_name YOUR-DOMAIN_HERE;
        root /var/www/html;
    }
    

    Restart nginx

    systemctl restart nginx
    

    At this point, nginx will serve the web site from /var/www/html folder. Lets get an SSL certficate using certbot

    certbot --authenticator webroot --webroot-path /var/www/html --installer nginx -d YOUR-DOMAIN_HERE
    

    Once you have SSL, we need to replace the nginx config with proper nginx config

    vi /etc/nginx/sites-enabled/odoo.conf
    

    Replace everything in the file with following content.

    upstream odoo {
        server 127.0.0.1:8069;
    }
    
    upstream odoo-chat {
        server 127.0.0.1:8072;
    }
    
    server {
        listen 80;
        server_name YOUR-DOMAIN-HERE;
    
        location ^~ /.well-known/acme-challenge/ {
            root /var/www/html;
        }
    
        location / {
            return 301 https://YOUR-DOMAIN-HERE$request_uri;
        }
    }
    
    server {
        listen 443 ssl http2;
        server_name YOUR-DOMAIN-HERE;
        ssl_certificate /etc/letsencrypt/live/YOUR-DOMAIN-HERE/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/YOUR-DOMAIN-HERE/privkey.pem;
        include /etc/letsencrypt/options-ssl-nginx.conf;
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
        resolver 8.8.8.8 8.8.4.4;
        access_log /var/log/nginx/odoo-access.log;
        error_log /var/log/nginx/odoo-error.log;
    
        proxy_read_timeout 720s;
        proxy_connect_timeout 720s;
        proxy_send_timeout 720s;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
    
        location / {
            proxy_redirect off;
            proxy_pass http://odoo;
        }
    
        location /longpolling {
            proxy_pass http://odoo-chat;
        }
    
        location ~* /web/static/ {
            proxy_cache_valid 200 90m;
            proxy_buffering    on;
            expires 864000;
            proxy_pass http://odoo;
        }
    
        gzip_types text/css text/less text/plain text/xml application/xml application/json application/javascript;
        gzip on;
    }
    

    Restart nginx

    systemctl restart nginx
    

    At this point, if you go to your web site, you will see Odoo install screen. All you need to do here is enter a database name and fill some information. You can select any database name, installer will create the database.

  • Docker delete container after running

    When you run a docker image, it create a container and run it. After docker container stop, container stays, so you can use it again if required.

    Some times, you need to delete docker container after it is run. This is useful if your docker container is just a command line executable. In my case, docker container have ffmpeg in it, i don’t want container left over after i executed ffmpeg command.

    To auto delete container after execution, use –rm option.

    docker run --rm DOCKER_IMAGE
    

    Example

    docker run --rm --name ffmpeg jrottenberg/ffmpeg:3.2-ubuntu -format
    
  • Run PostgreSQL in Docker

    To run PostgreSQL on docker, create a directory for saving the data presistant

    mkdir -p /opt/my-postgresql
    

    run docker container

    docker run --name my-postgresql \
        -p 5432:5432 \
        -e POSTGRES_PASSWORD=serverok123 \
        -e POSTGRES_USER=serverok \
        -e POSTGRES_DB=serverok \
        -v /opt/my-postgresql:/var/lib/postgresql/data \
        -d postgres
    

    In above, change the value for POSTGRES_DB, POSTGRES_USER and POSTGRES_PASSWORD as needed.

    Connect to PostgreSQL server

    To connect to PostgreSQL server, run

    docker container exec -ti my-postgresql bash
    

    Now you are inside PostgreSQL conainer, to login, run

    psql -U serverok -W
    

    It will ask for password. Once you enter password, you will be in PostgreSQL command line.

    See docker