Docker install Nginx container

#Introduction

In this tutorial, I will use Docker to install an Nginx web server. How to set up an Nginx web server in a Docker container. Now, let go Docker install Nginx container.

Docker as a platform container. I will install Docker on Debian/Ubuntu and install the Nginx container from Docker Hub.

Install Docker on Ubuntu here

Docker install Nginx container

Run Nginx Container Using Docker. I will pull an Nginx image from the docker hub.

$ docker pull nginx

List the Docker images as command below

$ docker images

Create Docker Volume for Nginx

$ docker volume create nginx-data-persistent

Get the docker volume information as command below

$ docker volume inspect nginx-data-persistent

Building a Web Page to Serve on Nginx

Create an HTML file

$ sudo vi /var/lib/docker/volumes/nginx-data-persistent/_data/index.html

The content is as below:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Learn Docker at DevopsRoles.com</title>
</head>
<body>
    <h1>Learn Docker With DevopsRoles.com</h1>   
</body>
</html>

Start the Nginx container with persistent data storage. Data storage location “/var/lib/docker/volumes/nginx-data-persistent/_data” on Host Ubuntu and the path in the container is “/usr/share/nginx/html” Run command as below:

$ docker run -d --name nginx-server -p 8080:80 -v nginx-data-persistent:/usr/share/nginx/html nginx

Explain:

  • d: run the container in detached mode
  • name: name of the container to be created
  • p: port to be mapped with host, Example: host port is 8080 and guest port is 80
  • v: name of docker volume

you can create a symlink of the docker volume directory

$ sudo ln -s /var/lib/docker/volumes/nginx-data-persistent/_data /nginx-data

Option

Access into Nginx container with the command below

$ docker exec -it nginx-server /bin/bash

Now, you can stop docker container apache

docker stop nginx-server

and remove it:

docker rm nginx-server

You can clean up and delete the image that was used in the container.

docker image remove nginx

Youtube Docker install Nginx container

Conclusion

You have successfully installed and run an Nginx container using Docker. You can now customize the Nginx configuration, serve your own website, or explore additional Nginx features and settings. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Docker install Apache Web Server

#Introduction

In this tutorial, I will use Docker to install an apache web server. How to set up Apache web server in a Docker container. Now, let go Docker install Apache Web Server.

Docker as a platform container. I will install Docker on Debian/Ubuntu and install Apache 2.4 container from Docker Hub.

Install Docker on Ubuntu here

Setting up the Apache Docker Container

For example, I will install Apache 2.4 container named devops-roles. Use an image called httpd:2.4 from Docker Hub. and detached from the current terminal.

Host port is 8080 to be redirected to guest port 80 on the container. I will serve a simple web page form /home/vagrant/website.

Docker install Apache web server

docker run -itd --name devops-roles -p 8080:80 -v /home/vagrant/website/:/usr/local/apache2/htdocs/ httpd:2.4

Check Docker Apache container running as command below

docker ps

To created index.html file inside /home/vagrant/website directory.

sudo vi /home/vagrant/website/index.html

The content as below

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Learn Docker at DevopsRoles.com</title>
</head>
<body>
    <h1>Learn Docker With DevopsRoles.com</h1>   
</body>
</html>

Open web browser type server-ip:8080/index.html

The output terminal as below

Now, you can stop docker container apache

docker stop devops-roles

and remove it:

docker rm devops-roles

You can clean up and delete the image that was used in the container.

docker image remove httpd:2.4

Via Youtube

Conclusion

You have to Docker install Apache Web Server. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Docker Containers Share Data

Introduction

In this blog, we will explore various methods of data sharing in Docker containers and how they can be effectively used in your projects. Now, let go Docker Containers Share Data.

Docker containers can share data using various mechanisms provided by Docker. Here are a few ways to share data between Docker containers.

I will deploy 2 containers using docker to share data between containers.

Prerequisites

  • Host OS: Ubuntu 21.04
  • Installed Docker

Create a Volume for Docker containers share data

Volumes are a fundamental feature in Docker that enable data persistence and sharing between containers and the host system.

When you create a volume, it acts as a dedicated storage location that can be mounted into one or more containers. The data stored in a volume persists even if the container using it is removed.

We will create a Volume to save our data as command below:

docker volume create --name persistent-data-devops

The volume is created in the /var/lib/docker/volumes directory.

vagrant@devopsroles:~$ sudo ls /var/lib/docker/volumes/persistent-data-devops/_data/test.txt
/var/lib/docker/volumes/persistent-data-devops/_data/test.txt

For example, We will deploy the first container which will use the persistent volume.

docker run -it --name=container1 -v persistent-data-devops:/data ubuntu:latest
  • The container named: container1
  • mount the persistent-data-devops volume into the /data directory within the new container

Login new container and create a new file

echo "Hello, www.devopsroles.com" >> /data/test.txt

We’ll now deploy a second container as command below

docker run -it --name=container2 -v persistent-data-devops:/data ubuntu:latest

Login second container and display content

cat /data/test.txt

Edit /data/test.txt file. I use the vim command line.

Add the following at the bottom of the file:

This data share between containers 1 and 2

The output terminal as below

vagrant@devopsroles:~$ docker run -it --name=container2 -v persistent-data-devops:/data ubuntu:latest

root@ed16b6be95f8:/# cat /data/test.txt
Hello, www.devopsroles.com

root@ed16b6be95f8:/# vim /data/test.txt
root@ed16b6be95f8:/# cat /data/test.txt
Hello, www.devopsroles.com
This data share between containers 1 and 2

Exit the running container with the exit command. You can stop and remove them with the commands:

docker stop ID
docker rm ID

After stopping and removing docker container1, we will deploy again, But data will remain data.

Youtube: Docker Containers Share Data

Conclusion

You have to Docker Containers Share Data. These are some of the common methods to share data between Docker containers. Choose the one that best suits your requirements based on the nature of the data and the use case you have in mind.

Data sharing is a crucial aspect of Docker containerization. By utilizing volumes, bind mounts, named volumes, Docker Compose, and Docker networks, you can effectively share data between containers and the host system. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Docker deploy MySQL and phpMyAdmin

#Introduction

In this tutorial, How to use Docker deploy MySQL and phpMyAdmin.

Docker is a software platform designed to make it easier to create, deploy, and run applications by using containers.

MySQL Database Service is a fully managed database service to deploy cloud-native applications. Quota from MySQL.

Prerequisites Docker deploy MySQL and phpMyAdmin

  • Host OS: Ubuntu 21.04
  • Installed Docker

Deploy the MySQL Database

First I will create a volume for MySQL to remain persistent. I will create a volume name is mysql-volume with the command below:

docker volume create mysql-volume

The output terminal is as below:

vagrant@devopsroles:~$ docker volume create mysql-volume
mysql-volume
vagrant@devopsroles:~$ docker volume ls
DRIVER    VOLUME NAME
local     1b944b2bc6253d6ef43a7fe8c0b57f7e070a219d495a69d89ee5e33ab3ffc48f
local     4f63522a2fe6eec851e2502fc56bbed0706a73df8e2a119ef1a9382c234f1b5b
local     8c2473be65a52c7a0a47e2d7b48b6781f29255f3ef6372b60e4c227644ff0844
local     c6e1ca4cc9617ca9031d974f4d19a5efbac96102850aa255d07c9dc53bd7f6e4
local     c509424aaaeda0374dc1d3d849bc245a183e865cddffa4bc1606d736ee3fb615
local     cb6583b8ad3d474f06e6c8fef30f5d4d11cb1a51e69ca0cc5d2df15a9deae1c3
local     ghost-blog_ghost
local     ghost-blog_mysql
local     my-postgres-db-db
local     mysql-volume

After our volume ready, we will deploy the MySQL container with named is devops_mysql and connect it to the volume with the command below:

docker run --name=devops_mysql -p3306:3306 -v mysql-volume:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123abc@ -d mysql/mysql-server

The output terminal as below

vagrant@devopsroles:~$ docker run --name=devops_mysql -p3306:3306 -v mysql-volume:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123abc@ -d mysql/mysql-server
Unable to find image 'mysql/mysql-server:latest' locally
latest: Pulling from mysql/mysql-server
221c7ea50c9e: Pull complete
d32a20f3a6af: Pull complete
28749a63c815: Pull complete
3cdab959ca41: Pull complete
30ceffa70af4: Pull complete
e4b028b699c1: Pull complete
3abed4e8adad: Pull complete
Digest: sha256:6fca505a0d41c7198b577628584e01d3841707c3292499baae87037f886c9fa2
Status: Downloaded newer image for mysql/mysql-server:latest
8b5a319d3cdaac3cd34046e6a32d8a6df25cbf17d28b3e83ac759389d2916e0c
vagrant@devopsroles:~$ docker ps
CONTAINER ID   IMAGE                COMMAND                  CREATED          STATUS                             PORTS                                                        NAMES
8b5a319d3cda   mysql/mysql-server   "/entrypoint.sh mysq…"   16 seconds ago   Up 14 seconds (health: starting)   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060-33061/tcp   devops_mysql

Deploy the phpMyAdmin Container

I will deploy the phpMyAdmin Container. Create a volume for phpMyAdmin with the command line as below

docker volume create phpmyadmin-volume

The output terminal is as below:

vagrant@devopsroles:~$ docker volume create phpmyadmin-volume
phpmyadmin-volume
vagrant@devopsroles:~$ docker volume ls | grep phpmyadmin-volume
local     phpmyadmin-volume

deploy the phpMyAdmin container with the command:

docker run --name devops-phpmyadmin -v phpmyadmin-volume:/etc/phpmyadmin/config.usr.inc.php --link devops_mysql:db -p 82:80 -d phpmyadmin/phpmyadmin

The output terminal is as below:

vagrant@devopsroles:~$ docker run --name devops-phpmyadmin -v phpmyadmin-volume:/etc/phpmyadmin/config.usr.inc.php --link devops_mysql:db -p 82:80 -d phpmyadmin/phpmyadmin
b505829b235660a4a4881cbc6df777b8592a32b4bd014cc543e02238c3b1f409
vagrant@devopsroles:~$ docker ps | grep  devops-phpmyadmin
b505829b2356   phpmyadmin/phpmyadmin   "/docker-entrypoint.…"   12 seconds ago   Up 11 seconds            0.0.0.0:82->80/tcp, :::82->80/tcp                            devops-phpmyadmin
vagrant@devopsroles:~$

The explanation of the above command

  • Deploying a container named devops-phpmyadmin
  • Linking to devops_mysql database
  • external port is 82
  • Internal port is 80
  • running the container in daemon mode (with the -d option)

How to Access phpMyAdmin

Open a web browser and point it to http://SERVER:82

Log in with the username root and the password you used when you deployed the MySQL container.

For example, the username is root and the Password is 123abc@

Can not access MySQL docker as the picture below

How to fix it

docker exec -it devops_mysql mysql -u root -p
update mysql.user set host='%' where user='root' and host = 'localhost';
flush privileges;

The result, Login access to phpMyAdmin

How to access MySQL and phpMyAdmin containers

docker exec -it devops_mysql /bin/bash
docker exec -it devops-phpmyadmin /bin/bash

Via youtube

Conclusion

You have to Docker deploy MySQL and phpMyAdmin. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Install pyenv and manage multiple python versions

Introduction

In this post, How to Install pyenv and manage multiple python versions.

  • Pyenv is a fantastic tool for installing and managing multiple Python versions. It also offers the ability to quickly switch from one version of Python to another.
  • Pyenv integrates with the Virtualenv plugin to support creating virtual environments (virtual environments), and library projects will be installed in isolation in this virtual environment without affecting the system.

Install Dependencies

On Rocky Linux / Centos

sudo yum install zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel

On Ubuntu

sudo apt-get install make build-essential libssl-dev zlib1g-dev libbz2-dev \
  libreadline-dev libsqlite3-dev wget curl libncurses5-dev libncursesw5-dev \
  xz-utils tk-dev libffi-dev liblzma-dev

Install pyenv

You can view the installation instructions from Pyenv’s homepage on Github or use the command below

$ curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash

The output terminal install pyenv as below

vagrant@devopsroles:~$ curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   148  100   148    0     0    778      0 --:--:-- --:--:-- --:--:--   778
100  1687  100  1687    0     0   5477      0 --:--:-- --:--:-- --:--:-- 17214
Cloning into '/home/vagrant/.pyenv'...
remote: Enumerating objects: 882, done.
remote: Counting objects: 100% (882/882), done.
remote: Compressing objects: 100% (438/438), done.
remote: Total 882 (delta 493), reused 565 (delta 338), pack-reused 0
Receiving objects: 100% (882/882), 460.45 KiB | 1.92 MiB/s, done.
Resolving deltas: 100% (493/493), done.
Cloning into '/home/vagrant/.pyenv/plugins/pyenv-doctor'...
remote: Enumerating objects: 11, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 11 (delta 1), reused 3 (delta 0), pack-reused 0
Receiving objects: 100% (11/11), 38.71 KiB | 1.49 MiB/s, done.
Resolving deltas: 100% (1/1), done.
Cloning into '/home/vagrant/.pyenv/plugins/pyenv-installer'...
remote: Enumerating objects: 16, done.
remote: Counting objects: 100% (16/16), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 16 (delta 1), reused 10 (delta 0), pack-reused 0
Receiving objects: 100% (16/16), 5.78 KiB | 5.78 MiB/s, done.
Resolving deltas: 100% (1/1), done.
Cloning into '/home/vagrant/.pyenv/plugins/pyenv-update'...
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 10 (delta 1), reused 5 (delta 0), pack-reused 0
Receiving objects: 100% (10/10), done.
Resolving deltas: 100% (1/1), done.
Cloning into '/home/vagrant/.pyenv/plugins/pyenv-virtualenv'...
remote: Enumerating objects: 61, done.
remote: Counting objects: 100% (61/61), done.
remote: Compressing objects: 100% (55/55), done.
remote: Total 61 (delta 11), reused 22 (delta 0), pack-reused 0
Receiving objects: 100% (61/61), 37.94 KiB | 2.11 MiB/s, done.
Resolving deltas: 100% (11/11), done.
Cloning into '/home/vagrant/.pyenv/plugins/pyenv-which-ext'...
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 10 (delta 1), reused 6 (delta 0), pack-reused 0
Receiving objects: 100% (10/10), done.
Resolving deltas: 100% (1/1), done.

WARNING: seems you still have not added 'pyenv' to the load path.


# See the README for instructions on how to set up
# your shell environment for Pyenv.

# Load pyenv-virtualenv automatically by adding
# the following to ~/.bashrc:

eval "$(pyenv virtualenv-init -)"

Then insert the following 3 lines into the shell’s config file ~/.bashrc

export PATH="/home/vagrant/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

The output terminal config file ~/.bashrc as below

[vagrant@devopsroles ~]$ cat .bashrc
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific environment
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
then
    PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi
export PATH

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions
export PATH="/home/vagrant/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
[vagrant@devopsroles ~]$ source .bashrc
[vagrant@devopsroles ~]$ pyenv --version
pyenv 2.2.4
[vagrant@devopsroles ~]$

use pyenv

For example, I will introduce how to use pyenv to set up a virtual environment using python 3.6.6 for the project demo. Path ~/projects/demo

$ pyenv install 3.6.6

The output terminal as below

[vagrant@devopsroles ~]$ pyenv install 3.6.6

Installing Python-3.6.6...
Installed Python-3.6.6 to /home/vagrant/.pyenv/versions/3.6.6
[vagrant@devopsroles ~]$

If the installation fails, maybe your system lacks the necessary libraries for compiling, install the missing libraries here

Create a virtual environment with virtualenv, which uses Python 3.6.6.

pyenv virtualenv 3.6.6 app

Enable environment settings

pyenv activate app

To deactivate environment settings

pyenv deactivate app

Useful Commands

Conclusion

You have to Install pyenv and manage multiple python versions. I hope will this your helpful. Thank you for reading the DevopsRoles page! Install pyenv, Install pyenv.

Step-by-Step Guide: Deploy Ghost Blog with docker

Introduction

In this tutorial, How to Deploy Ghost Blog with docker. cms Ghost is a popular content creation platform that’s written in JavaScript with Node.js. It’s open-source software.

Docker has become a popular choice for deploying applications due to its ease of use, scalability, and portability. If you’re looking to start a blog using Ghost, a powerful and flexible open-source blogging platform, using Docker can simplify the deployment process.

We will use Docker to quickly Ghost blog. First, we have installed Docker and Docker Compose on your host.

Prerequisites

Before we get started, make sure you have Docker and Docker Compose installed on your server or local machine.

Deploy a Ghost Container

We will start a basic Ghost site with the docker command as below:

docker run -d -p 2368:2368 --name simple-ghost ghost:4

Ghost the default port is 2368. We will view the site via http://localhost:2368 or http://localhost:2368/ghost to access the Ghost admin panel.

We will first run settings to finalize your Ghost installation and create an initial user account.

This approach is if we just trying out Ghost. However, we have not set up persistent storage yet so your data will be lost when the container stops.

We will use uses Docker Compose to set up Ghost with a Docker volume. Mount a volume to the /var/lib/ghost/content directory to store Ghost’s data outside the container.

Example docker-compose.yml file

version: "3"
services:
  ghost:
    image: ghost:4
    ports:
      - 8080:2368
    environment:
      url: https://ghost.devopsroles.com
    volumes:
      - ghost:/var/lib/ghost/content
    restart: unless-stopped
volumes:
  ghost:

Now use Compose to bring up your site:

docker-compose up -d

External Database

Ghost defaults to using an SQLite database that’s stored as a file in your site’s content directory.

services:
  ghost:
    # ...
    environment:
      database__client: mysql
      database__connection__host: ghost_mysql
      database__connection__user: root
      database__connection__password: databasePw
      database__connection__database: ghost

  ghost_mysql:
    image: mysql:5.7
    expose:
      - 3306
    environment:
      MYSQL_DATABASE: ghost
      MYSQL_ROOT_PASSWORD: databasePw
    volumes:
      - mysql:/var/lib/mysql
    restart: unless-stopped

volumes:
  mysql:

Summary Ghost blog docker-compose

version: "3"
services:
  ghost:
    image: ghost:4
    ports:
      - 8080:2368
    environment:
      url: https://ghost.devopsroles.com
    volumes:
      - ghost:/var/lib/ghost/content
    restart: unless-stopped
    environment:
      database__client: mysql
      database__connection__host: ghost_mysql
      database__connection__user: root
      database__connection__password: databasePw
      database__connection__database: ghost

  ghost_mysql:
    image: mysql:5.7
    expose:
      - 3306
    environment:
      MYSQL_DATABASE: ghost
      MYSQL_ROOT_PASSWORD: databasePw
    volumes:
      - mysql:/var/lib/mysql
    restart: unless-stopped
volumes:
  ghost:
  mysql:

Proxying Traffic to Your Container

Add NGINX to your host:

sudo apt update
sudo apt install nginx

# Allow HTTP/HTTPS traffic through the firewall
sudo ufw allow 80
sudo ufw allow 443

Define an NGINX host for your site in /etc/nginx/sites-available/ghost.devopsroles.com

server {
    
    server_name ghost.devopsroles.com;
    index index.html;

    access_log /var/log/nginx/ghost_access.log;
    error_log /var/log/nginx/ghost_error.log error;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_redirect off;
        proxy_set_header Host $http_host;
        proxy_set_header X-Original-IP $remote_addr;
    }

}

Create symbolic link

sudo ln -s /etc/nginx/sites-available/ghost.devopsroles.com /etc/nginx/sites-enabled/ghost.devopsroles.com

Restart Nginx service

sudo systemctl restart nginx

The result is Deploy cms Ghost Blog with docker Nginx

How to Deploy Ghost Blog with Docker via Youtube

Conclusion

You’ve successfully deployed a Ghost blog using Docker, taking advantage of the benefits of containerization for managing your blog.

With your cms Ghost blog now live, you can explore additional Docker features to enhance your blog’s capabilities, such as using custom themes, adding plugins, and scaling your blog to handle increasing traffic.

I hope will this your helpful. Thank you for reading the DevopsRoles page!

How to install Docker compose on Ubuntu

Introduction

In this tutorial, How to install Docker compose on Ubuntu 21.04. Docker is an open platform that allows you to build, test, and deploy applications quickly.

Docker Compose is used for defining and running multi-container Docker applications. It allows users to launch, execute, communicate with a single coordinated command. Docker Compose is yet another useful Docker tool.

Prerequisites

  • A system running Ubuntu 21.04
  • A user account with sudo privileges
  • Docker installed on Ubuntu 21.04

Step 1: Update your system

Update your existing packages:

sudo apt update

Step 2: Install curl package

sudo apt install curl -y

Step 3: Download the Latest Docker compose Version

Docker-compose new stable versions, refer to the official list of releases on GitHub.

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Step 4: Change File Permission

sudo chmod +x /usr/local/bin/docker-compose

Step 5: Check Docker Version

To verify the installation, check the Docker compose version by command below:

docker-compose --version

Uninstall Docker compose on Ubuntu

Delete the Binary

sudo rm /usr/local/bin/docker-compose

Uninstall the Package

sudo apt remove docker-compose

Remove Software Dependencies

sudo apt autoremove

Via Youtube

Conclusion

You have to install Docker compose on Ubuntu 21.04. I hope will this your helpful. Thank you for reading the DevopsRoles page!

How to install Docker on Ubuntu

Introduction

This tutorial explains how to install Docker on Ubuntu 21.04, highlighting Docker as an efficient open platform for building, testing, and deploying applications. Docker simplifies and accelerates the deployment process, making it less time-consuming to build and test applications. The guide is ideal for anyone looking to streamline their development workflow using Docker on the Ubuntu system.

How to install Docker on Ubuntu

To install Docker on Ubuntu, you can follow these steps:

Prerequisites

  • A system running Ubuntu 21.04
  • A user account with sudo privileges

Step 1: Update your system

Update your existing packages:

sudo apt update

Step 2: Install the curl package

sudo apt install curl -y

Step 3: Download the Latest Docker Version

curl -fsSL https://get.docker.com -o get-docker.sh

Step 4: Install Docker

sh get-docker.sh

Step 5: To make sure that the current user can access the docker daemon

To avoid using sudo for docker activities, add your username to the Docker Group

sudo usermod -aG docker $USER

Step 6: Check Docker Version

To verify the installation, check the Docker version by command below:

docker --version

Uninstall Docker on Ubuntu

Check the package installed docker on Ubuntu.

dpkg -l | grep -i docker

Use the apt remove command to uninstall Docker on Ubuntu.

sudo apt-get purge docker-ce docker-ce-cli docker-ce-rootless-extras docker-scan-plugin
sudo rm -rf /var/lib/docker

Remove Software Dependencies

sudo apt autoremove

Conclusion

How to install Docker on Ubuntu 21.04. After completing these steps, Docker should be successfully installed on your Ubuntu system, and you can start using Docker commands to manage containers and images. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Exploring the fd Command in Linux: A Powerful Find Alternative for Efficient File Searches

Introduction

In this tutorial, how to use the fd command in Linux. fd command-line tool to find files in the file system. this tool is very simple.

The “fd” command is not a standard command in Linux. It seems that you might be referring to a specific command that is not part of the core Linux utilities.

What is the ‘fd’ Command?

The ‘fd’ command is a powerful and user-friendly tool that facilitates file searches within the Linux file system.

Although not a native Linux command, it is often considered a better and more intuitive alternative to the ‘find’ command. ‘fd’ is built on Rust, which contributes to its speed and efficiency.

Install fd command

Before you can start using ‘fd’, you need to install it on your Linux system. In this section, we’ll cover how to install ‘fd’ using popular package managers like ‘apt’ and ‘yum’, as well as from source.

Using apt to install fd on Ubuntu Server.

sudo apt-get install fd-find

(Optional) Create an alias for fd that refers to fdfind.

alias fd=fdfind

(Optional) To make the alias permanent.

vi ~/.bashrc
#Add this entry to the bashrc file
alias fd=fdfind

Use the fd command in Linux

Before using the fd command in Linux, we need to read the help of the command.

# fd --help

The output terminal as below

Find all files and directories starting with “abc” followed by any number of digits, you can use the following command:

fd -e "^abc\d+"

find all files that were changed before a specified number of days

$ fd index /home/vagrant --changed-before 365d

Finding Files Inside a Specific Directory

$ fd password /etc

Finding Files Based on Extension

$ fd -e html

Finding Hidden Files

$ fd -H bash

More details information about fd command.

man fd

Conclusion

fd command is a simple command in Linux. It uses the number of lines of files. These are just a few examples of how you can use the “fd” command.

For more advanced usage and options, you can refer to the documentation or help of the specific “fd” implementation you have installed on your system, as there are multiple versions available. Thank you for reading the DevopsRoles page!

Step-by-Step: Create Docker Image from a Running Container

Introduction

In this tutorial, We will deploy a container Nginx server, modify it, and then create a new image from that running container. Now, let’s go to Create Docker Image from a Running Container.

What does docker mean?

Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries, and configuration files Quota from Wikipedia

Install Docker on Ubuntu

If you don’t already have Docker installed, let’s do so. I will install Docker on Ubuntu Server. I use Ubuntu version 21.04 to install Docker.

To install Docker on Your Ubuntu server command below

sudo apt-get install docker.io -y

Add your user to the docker group with the command below

sudo usermod -aG docker $USER

Logging out and logging back in to ensure the changes take effect.

Create Docker Image from a Running Container

Create the New Container

We will create the new container with the command below:

sudo docker create --name nginx-devops -p 80:80 nginx:alpine
  • Create a new container: nginx-devops
  • Internal port ( Guest ): 80
  • External ( host ) port: 80
  • Use image: nginx:alpine

The output terminal is the picture below:

Start the Nginx container with the command below

After creating a new container, you open a Web browser and point it. You see the NGINX welcome page.

Modify the Existing Container

We will create a new index.html page for Nginx.

To do this, create a new page with the command below

vi index.html

In that file, paste the content (you can modify it to say whatever you want):

<html>
    <h2>DevopsRoles.com</h2>
</html>

Save and close the file

We copy index.html to the document root on nginx-devops container with the command below:

sudo docker cp index.html nginx-devops:/usr/share/nginx/html/index.html

you refresh the page in your web browser, you see a new welcome as the picture below:

Create a New Image

How to create a new image that includes the changes. It is very simple.

  1. We will commit the changes with the command below:
sudo docker commit nginx-devops

we will list all current images with the command below

sudo docker images

2. We will tag for docker-base-image

sudo docker tag IMAGE_ID nginx-devops-container

Where IMAGE_ID is the actual ID of your new container.

you’ll see something like this:

sudo docker images

In the output terminal step, 1 and step 2 as in the picture below

You’ve created a new Docker image from a running container.

Let’s stop and remove the original container. we will remove nginx-devops container with the command below

sudo docker ps -a
sudo docker stop ID
sudo docker rm ID

Where ID is the first four digits of the original container.

You could deploy a container from the new image with a command like:

sudo docker create --name nginx-new -p 80:80 nginx-devops-container:latest

The output terminal as the command below

vagrant@devopsroles:~$ sudo docker ps -a
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS         PORTS                               NAMES
fe3d2e383b80   nginx:alpine   "/docker-entrypoint.…"   11 minutes ago   Up 8 minutes   0.0.0.0:80->80/tcp, :::80->80/tcp   nginx-devops
vagrant@devopsroles:~$ sudo docker stop fe3d2e383b80
fe3d2e383b80
vagrant@devopsroles:~$ sudo docker rm fe3d2e383b80
fe3d2e383b80
vagrant@devopsroles:~$ sudo docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
vagrant@devopsroles:~$ sudo docker create --name nginx-new -p 80:80 nginx-devops-container:latest
91175e61375cf86fc935c55081be6f81354923564c9c0c0f4e5055ef0f590600
vagrant@devopsroles:~$ sudo docker ps -a
CONTAINER ID   IMAGE                           COMMAND                  CREATED              STATUS    PORTS     NAMES
91175e61375c   nginx-devops-container:latest   "/docker-entrypoint.…"   About a minute ago   Created             nginx-new
vagrant@devopsroles:~$ sudo docker start 91175e61375c
91175e61375c
vagrant@devopsroles:~$

What is the difference between docker commit and docker build?

docker commit creates an image from a container’s state, while docker build creating an image from a Dockerfile, allowing for a more controlled and reproducible build process.

Refresh your web browser and you should, once again, see the DevopsRoles page, New Stack! Welcome page.

YouTube: Create Docker Image from a Running Container

Conclusion

Create Docker Image from a Running Container is a powerful feature that enables you to capture the exact state of an application at any given moment. By following the steps outlined in this guide, you can easily commit a running container to a new image and use advanced techniques to add tags, commit messages, and author information. Whether you’re looking to back up your application, replicate environments, or share your work with others, this process provides a simple and effective solution. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Devops Tutorial

Exit mobile version