Tag: docker

  • How to install docker on AlmaLinux 8

    How to install docker on AlmaLinux 8

    To install docker on AlmaLinux, run the following commands

    Install yum-utils

    dnf install -y yum-utils

    Add docker repository

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

    Install Docker CE with

    dnf install docker-ce

    Enable docker

    systemctl enable docker

    Start Docker

    systemctl start docker

    To verify if docker is working properly, run

    docker run hello-world
    

    Example

    [root@cloud ~]# docker run hello-world
    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    2db29710123e: Pull complete 
    Digest: sha256:94ebc7edf3401f299cd3376a1669bc0a49aef92d6d2669005f9bc5ef028dc333
    Status: Downloaded newer image for hello-world:latest
    
    Hello from Docker!
    This message shows that your installation appears to be working correctly.
    
    To generate this message, Docker took the following steps:
     1. The Docker client contacted the Docker daemon.
     2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
        (amd64)
     3. The Docker daemon created a new container from that image which runs the
        executable that produces the output you are currently reading.
     4. The Docker daemon streamed that output to the Docker client, which sent it
        to your terminal.
    
    To try something more ambitious, you can run an Ubuntu container with:
     $ docker run -it ubuntu bash
    
    Share images, automate workflows, and more with a free Docker ID:
     https://hub.docker.com/
    
    For more examples and ideas, visit:
     https://docs.docker.com/get-started/
    
    [root@cloud ~]# 

    See 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

  • 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.

  • bash: ps: command not found

    On a docker image, when i run ps, i get error

    root@2efea503e8b7:~# ps
    bash: ps: command not found
    root@2efea503e8b7:~# 
    

    To install ps on Debian/Ubuntu, run

    apt -y install procps
    
  • 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

  • Docker compose start container on boot

    I have a docker container, that i need to start on server boot.

    The docker-compose.yml file i used to create this docker container is

    [root@cp03 serverok-rubycms]# cat docker-compose.yml 
    version: '3'
    services:
      web:
        image: serverok/rubycms:1.0
        command: bash -c "rm -f tmp/pids/server.pid && cd /myapp && source /etc/profile.d/rvm.sh && script/server -e production"
        volumes:
          - /home/naiwnyc/cms:/myapp
        ports:
          - "3000:3000"
    [root@cp03 serverok-rubycms]# 
    

    With above docker-compose.yml file. i have to start docker container manually after server reboot.

    To make it auto start, add the line

        restart: always
    

    Here is the modified docker-compose.yml file.

    [root@cp03 serverok-rubycms]# cat docker-compose.yml 
    version: '3'
    services:
      web:
        image: serverok/rubycms:1.0
        restart: always
        command: bash -c "rm -f tmp/pids/server.pid && cd /myapp && source /etc/profile.d/rvm.sh && script/server -e production"
        volumes:
          - /home/naiwnyc/cms:/myapp
        ports:
          - "3000:3000"
    [root@cp03 serverok-rubycms]#
    

    You need to rebuild docker container based on this docker-compose.yml file

    Change to the folder where your docker-compse.yml file is, in my case it was

    cd  ~/serverok-rubycms
    

    Run

    docker-compose down
    docker-compose up -d
    
  • docker-compose: error while loading shared libraries

    When running docker-compose on CentOS 7, i get following error

    [root@cp03 serverok-rubycms]# docker-compose up 
    docker-compose: error while loading shared libraries: libz.so.1: failed to map segment from shared object: Operation not permitted
    [root@cp03 serverok-rubycms]#
    

    To fix the error, do the following

    mv /usr/local/bin/docker-compose /usr/local/bin/docker-compose-bin
    

    Now create a new file

    vi /usr/local/bin/docker-compose
    

    Add following content

    #!/bin/bash
    
    export TMPDIR=/opt/compose-tmp
    /usr/local/bin/docker-compose-bin "$@"
    

    Make it executable

    chmod 755 /usr/local/bin/docker-compose
    

    Create temp folder

    mkdir -p /opt/compose-tmp
    

    Now docker-compose will work.