Category Archives: Docker

Master Docker with DevOpsRoles.com. Discover comprehensive guides and tutorials to efficiently use Docker for containerization and streamline your DevOps processes.

Install Docker Swarm cluster

#Introduction

In this tutorial, How to Install Docker Swarm cluster. Docker Swarm is a way to create a cluster for container deployment.

With a minute you can deploy the cluster up and running for high availability, failover, and scalability.

To install a Docker Swarm cluster, you will need multiple nodes or machines that will act as Swarm managers and workers

Here’s a step-by-step guide on how to install Docker Swarm

Prerequisites

  • Host OS: Ubuntu 21.04
  • 1 Controller.
  • 2 nodes.
  • Installed Docker on your controller and node.

How to install Docker Swarm cluster

1. Log into the Docker Swarm controller

We run the command line as below:

sudo apt-get update -y
sudo apt-get install ca-certificates curl gnupg lsb-release -y
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-get update -y 
sudo apt-get install docker-ce docker-ce-cli containerd.io -y
sudo systemctl enable --now docker
sudo usermod -aG docker $USER
newgrp docker

2. Log into Docker Swarm Node1

We run the command line as below:

sudo apt-get update -y
sudo apt-get install ca-certificates curl gnupg lsb-release -y
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-get update -y 
sudo apt-get install docker-ce docker-ce-cli containerd.io -y
sudo systemctl enable --now docker
sudo usermod -aG docker $USER
newgrp docker

3. Log into Docker Swarm Node2

We run the command line as below:

sudo apt-get update -y
sudo apt-get install ca-certificates curl gnupg lsb-release -y
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-get update -y 
sudo apt-get install docker-ce docker-ce-cli containerd.io -y
sudo systemctl enable --now docker
sudo usermod -aG docker $USER
newgrp docker

For example, as the picture below:

Back at the Server Docker Controller, initialize the swarm with as command below:

docker swarm init --advertise-addr 192.168.56.11

You can see with the join command that will look something as below

docker swarm join --token SWMTKN-1-1godvlo74ufchdrmck9earbshkxa2u91w7ss742bryl40f7c8i-aq684grkb94d7vaguh4aep7rt 192.168.56.11:2377

Log into Node1 run the command docker swarm join

Log into Node2 run the command docker swarm join

We will verify the result on the Server controller:

docker info

Conclusion

You have successfully installed a Docker Swarm cluster and deployed services to it. You can continue exploring Docker Swarm features to manage and scale your applications effectively. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Deploy a self-hosted Docker registry

Introduction

In this tutorial, How to Deploy a self-hosted Docker registry with self-signed certificates. How to access it from a remote machine.

To deploy a self-hosted Docker registry, you can use the official Docker Registry image.

Here’s a step-by-step Deploy a self-hosted Docker registry guide to help you.

Prepare your directories

I will create them on my user home directory, but you can place them in any directory.

mkdir ~/registry

Create subdirectories in the registry directory.

mkdir ~/registry/{certs,auth}

Go into the certs directory.

cd ~/registry/certs

Create a private key

openssl genrsa 1024 > devopsroles.com.key
chmod 400 devopsroles.com.key

The output terminal is as below:

Create a docker_register.cnf file with the content below:

nano docker_register.cnf

In that file, paste the following contents.

[req]

default_bits  = 2048

distinguished_name = req_distinguished_name

req_extensions = req_ext

x509_extensions = v3_req

prompt = no

[req_distinguished_name]

countryName = XX

stateOrProvinceName = N/A

localityName = N/A

organizationName = Self-signed certificate

commonName = 120.0.0.1: Self-signed certificate

[req_ext]

subjectAltName = @alt_names

[v3_req]

subjectAltName = @alt_names

[alt_names]


IP.1 = 192.168.3.7

Note: Make sure to change IP.1 to match the IP address of your hosting server.

Save and close the file.

Generate the key with:

openssl req -new -x509 -nodes -sha1 -days 365 -key devopsroles.com.key -out devopsroles.com.crt -config docker_register.cnf

Go into auth directory.

cd ../auth

Generate an htpasswd file

docker run --rm --entrypoint htpasswd registry:2.7.0 -Bbn USERNAME PASSWORD > htpasswd

Where USERNAME is a unique username and PASSWORD is a unique/strong password.

The output terminal is the picture below:

Now, Deploy a self-hosted Docker registry

Change back to the base registry directory.

cd ~/registry

Deploy the registry container with the command below:

docker run -d \

--restart=always \

--name registry \

-v `pwd`/auth:/auth \

-v `pwd`/certs:/certs \

-v `pwd`/certs:/certs \

-e REGISTRY_AUTH=htpasswd \

-e REGISTRY_AUTH_HTPASSWD_REALM="Registry Realm" \

-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \

-e REGISTRY_HTTP_ADDR=0.0.0.0:443 \

-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/devopsroles.com.crt \

-e REGISTRY_HTTP_TLS_KEY=/certs/devopsroles.com.key \

-p 443:443 \

registry:2.7.0

Now, you can access it from the local machine. however, you want to access it from a remote system. we need to add a ca.crt file. you need the copy the contents of the ~/registry/certs/devopsroles.com.crt file.

Login into your second machine

Create folder

sudo mkdir -p /etc/docker/certs.d/SERVER:443

where SERVER is the IP address of the machine hosting the registry.

Create the new file with:

sudo nano /etc/docker/certs.d/SERVER:443/ca.crt

paste the contents from devopsroles.com.crt ( from the hosting server) save and close the file.

How to do login into the new registry

From the second machine.

docker login -u USER -p https://SERVER:443

Where USER is the user you added when you generated the htpasswd file above.

Conclusion

You have successfully deployed a self-hosted Docker registry. You can now use it to store and share your Docker images within your network. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Deploy Redash data visualization dashboard

#Introduction

This tutorial, How to Deploy Redash data visualization dashboard helps use Docker.

You can deploy the powerful data visualization tool Redash as a Docker container.

Redash is a powerful data visualization tool that is built for fast access to data collected from various sources. Redash helps you make sense of your data

Requirements

  • Running instance of Ubuntu Server.
  • A user with sudo privileges.

To deploy Redash, a data visualization dashboard, you can follow these steps:

Install Docker

First, You need to install Docker on the Ubuntu server. Refer to How to install docker on Ubuntu Server. and Install Docker-compose on the Ubuntu Server. Refer to here.

Deploy Redash data visualization dashboard

You need to update your server at the latest.

sudo apt-get update
sudo apt-get upgrade -y

Deploy Redash

curl -O https://raw.githubusercontent.com/getredash/setup/master/setup.sh
chmod u+x setup.sh
sudo ./setup.sh

The deployment will take anywhere from 2-10 minutes.

The output terminal is as below:

Docker containers running Redash data visualization dashboard

How to access Redash

Open a web browser, and type http://ipaddress as in the picture below:

The Redash main page

You now have to deploy a data visualization tool. Next time, How to connect a data source to Redash.

Conclusion

You have successfully deployed the Redash data visualization dashboard and can now start creating visualizations and dashboards for your data. Continue exploring the Redash documentation and features to leverage its full capabilities for data visualization and analysis.

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

How to Docker install Oracle 12c: A Step-by-Step Guide

Introduction

In this quick-start tutorial, learn how to Docker install Oracle 12c. This guide provides straightforward steps for setting up Oracle 12c in a Docker container, allowing you to leverage the benefits of a virtualized environment for database management. Perfect for those seeking a practical approach to deploying Oracle 12c with Docker.

Requirements

  • You need an account on Docker. Create an account here.
  • Install or update Docker on your PC

Oracle Database 12c Docker Image

Oracle Database Enterprise Edition 12c is available as an image in the Docker Store.

The following figures show the checkout

Docker install Oracle 12c

How to start an Oracle Database Server instance.

  • Docker login
  • Pull Oracle Database Enterprise Edition 12.2.0.1
  • Run the Docker container from the image

The command line is below

$ docker login
$ docker pull store/oracle/database-enterprise:12.2.0.1
$ mkdir ~/oracle-db-data
$ chmod 775 ~/oracle-db-data
$ sudo chown 54321:54322  ~/oracle-db-data
$ docker run -d -it --name oracle-db-12c \
-p 1521:1521 \
-e DB_SID=ORADEV \
-e DB_PDB=ORADEVPDB \
-e DB_DOMAIN=oracledb.devopsroles.local \
-v ~/oracle-db-data:/ORCL \
store/oracle/database-enterprise:12.2.0.1

I created an oracle-db-data directory on the host system for data volume. This data volume is mounted inside the container at /ORCL

  • Container name oracle-db-12c
  • Host port 1521 and Guest port 1521
  • Environment variable:

Set the SID to ORADEV

Set the PDB to ORADEVPDB

Set the DB Domain to oracledb.devopsroles.local

The output terminal is as below:

vagrant@devopsroles:~$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: your_account
Password:

Login Succeeded

vagrant@devopsroles:~$ docker pull store/oracle/database-enterprise:12.2.0.1
12.2.0.1: Pulling from store/oracle/database-enterprise
4ce27fe12c04: Pull complete
9d3556e8e792: Pull complete
fc60a1a28025: Pull complete
0c32e4ed872e: Pull complete
b465d9b6e399: Pull complete
Digest: sha256:40760ac70dba2c4c70d0c542e42e082e8b04d9040d91688d63f728af764a2f5d
Status: Downloaded newer image for store/oracle/database-enterprise:12.2.0.1
docker.io/store/oracle/database-enterprise:12.2.0.1

vagrant@devopsroles:~$ mkdir ~/oracle-db-data
vagrant@devopsroles:~$ chmod 775 ~/oracle-db-data
vagrant@devopsroles:~$ sudo chown 54321:54322  ~/oracle-db-data

vagrant@devopsroles:~$ docker run -d -it --name oracle-db-12c \
> -p 1521:1521 \
> -e DB_SID=ORADEV \
> -e DB_PDB=ORADEVPDB \
> -e DB_DOMAIN=oracledb.devopsroles.local \
> -v ~/oracle-db-data:/ORCL \
> store/oracle/database-enterprise:12.2.0.1
7589a72bb9794d6408eb4b635772b22bc3e711210d3e4422ab0dce639a439c4a

You can check and monitor the container with the command lines below:

$ docker logs -f oracle-db-12c
$ docker ps --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}' -f name=oracle-db-12c

Oracle Database Setup

The default password to connect to the database with the sys user is Oradoc_db1. Check the character set which should be AL32UTF8

docker exec -it oracle-db-12c bash -c "source /home/oracle/.bashrc; sqlplus /nolog"

SQL> connect sys/Oradoc_db1@ORADEV as sysdba
SQL> alter session set container=ORADEVPDB;
SQL> show parameters db_block_size;
SQL> select value from nls_database_parameters where parameter='NLS_CHARACTERSET';

Create data and temp tablespace

SQL> 
--Create tablespace for new devopsroles Project 
CREATE TABLESPACE huupv_devopsroles_data DATAFILE '/u01/app/oracle/product/12.2.0/dbhome_1/data/huupv_devopsroles_data.db' SIZE 64M AUTOEXTEND ON NEXT 32M MAXSIZE 4096M EXTENT MANAGEMENT LOCAL;
 
--Create temp tablespace for new devopsroles Project
CREATE TEMPORARY TABLESPACE huupv_devopsroles_temp TEMPFILE '/u01/app/oracle/product/12.2.0/dbhome_1/data/huupv_devopsroles_temp.db' SIZE 64M  AUTOEXTEND ON NEXT 32M MAXSIZE 4096M EXTENT MANAGEMENT LOCAL;
  • Do not start with too large an initial size, because it can waste space.
  • Use a single block size (8K) for the whole DB
  • Do not allow individual data files to grow large (beyond 8-10Gb)

Create a user and assign a grant

SQL> 
--Create user for devopsroles schema
CREATE USER huupv_devopsroles IDENTIFIED BY huupv_devopsroles DEFAULT TABLESPACE huupv_devopsroles_data TEMPORARY TABLESPACE huupv_devopsroles_temp PROFILE default ACCOUNT UNLOCK;
 
--Assign grant to user 
GRANT CONNECT TO huupv_devopsroles;
GRANT RESOURCE TO huupv_devopsroles;
GRANT UNLIMITED TABLESPACE TO huupv_devopsroles;

Test the new scheme using a tool such as Oracle SQLDeveloper

The parameters to connect to the new scheme are:

  • Username/password: huupv_devopsroles/huupv_devopsroles
  • Hostname: 192.168.3.7
  • Service Name: ORADEVPDB.oracledb.devopsroles.local

Via youtube

Conclusions

While installing Oracle Database 12c on Docker is not officially supported by Oracle, which only offers Docker images for Database 18c and later, you can still proceed by following the outlined steps in this guide.

Keep in mind that these steps are unofficial and might present certain limitations or compatibility issues. For optimal results and support, consider using the officially provided Oracle Database versions on Docker. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Docker deploy MySQL cluster

Introduction

In this tutorial, How to use Docker deploy MySQL cluster and connect to the nodes from your local machine. We will be deploying the MySQL server with docker.

To deploy a MySQL cluster using Docker, you can use the MySQL official Docker images and Docker Compose. Here’s a step-by-step guide:

  • 1 Management node
  • 2 Data nodes
  • 2 SQL nodes

The nodes in the cluster are running on separate hosts in a network.

First, You have installed docker on your machine.

Docker deploy MySQL cluster

Step 1: Create the docker network.

I will create a network for MySQL cluster with the following docker command.

docker network create cluster --subnet=192.168.4.0/24

Step 2: Get the mysql docker repository

git clone https://github.com/mysql/mysql-docker.git
cd mysql-docker
git checkout -b mysql-cluster

I will change the IP address of each node to match the subnet. Open mysql-cluster/8.0/cnf/mysql-cluster.cnf file

For example

[ndbd default]
NoOfReplicas=2
DataMemory=80M
IndexMemory=18M


[ndb_mgmd]
NodeId=1
hostname=192.168.4.2
datadir=/var/lib/mysql

[ndbd]
NodeId=2
hostname=192.168.4.3
datadir=/var/lib/mysql

[ndbd]
NodeId=3
hostname=192.168.4.4
datadir=/var/lib/mysql

[mysqld]
NodeId=4
hostname=192.168.4.10

[mysqld]
NodeId=5
hostname=192.168.4.11

Open mysql-cluster/8.0/cnf/my.cnf and modify as below

[mysqld]
ndbcluster
ndb-connectstring=192.168.4.2
user=mysql

[mysql_cluster]
ndb-connectstring=192.168.4.2

Docker image build

docker build -t <image_name> <Path to docker file>
docker build -t mysql-cluster mysql-cluster/8.0

Step 3: Create the manager node.

docker run -d --net=cluster --name=management1 --ip=192.168.4.2 mysql-cluster ndb_mgmd

Step 4: Create the data nodes

docker run -d --net=cluster --name=ndb1 --ip=192.168.4.3 mysql-cluster ndbd
docker run -d --net=cluster --name=ndb2 --ip=192.168.4.4 mysql-cluster ndbd

Step 5: Create the SQL nodes.

docker run -d --net=cluster --name=mysql1 --ip=192.168.4.10 -e MYSQL_RANDOM_ROOT_PASSWORD=true mysql-cluster mysqld
docker run -d --net=cluster --name=mysql2 --ip=192.168.4.11 -e MYSQL_RANDOM_ROOT_PASSWORD=true mysql-cluster mysqld
docker run -it --net=cluster mysql-cluster ndb_mgm

The cluster management console will be loaded.

[Entrypoint] MySQL Docker Image 8.0.28-1.2.7-cluster
[Entrypoint] Starting ndb_mgm
-- NDB Cluster -- Management Client --
ndb_mgm>

Run show command

ndb_mgm> show
Connected to Management Server at: 192.168.4.2:1186
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @192.168.4.3  (mysql-8.0.28 ndb-8.0.28, Nodegroup: 0, *)
id=3    @192.168.4.4  (mysql-8.0.28 ndb-8.0.28, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.4.2  (mysql-8.0.28 ndb-8.0.28)

[mysqld(API)]   2 node(s)
id=4    @192.168.4.10  (mysql-8.0.28 ndb-8.0.28)
id=5    @192.168.4.11  (mysql-8.0.28 ndb-8.0.28)

ndb_mgm>

Step 7. Change the default passwords.

MySQL node 1:

The SQL nodes are created initially, with a random password. Get the default password.

docker logs mysql1 2>&1 | grep PASSWORD

To change the password, first, Input the password default at Step 7

docker exec -it mysql1 mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
FLUSH PRIVILEGES;

MySQL node 2:

The SQL nodes are created initially, with a random password. Get the default password.

docker logs mysql2 2>&1 | grep PASSWORD

To change the password, first, Input the password default at Step 7

docker exec -it mysql2 mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
FLUSH PRIVILEGES;

Step 8: Login and create a new database.

For example, I will create huupv an account on mysql1 and mysql2 containers and access any hosts.

# For mysql1
docker exec -it mysql1 mysql -uroot -p
CREATE USER 'huupv'@'%' IDENTIFIED BY '123456789';
GRANT ALL ON *.* TO 'huupv'@'%';
FLUSH PRIVILEGES;

# For mysql2
docker exec -it mysql2 mysql -uroot -p
CREATE USER 'huupv'@'%' IDENTIFIED BY '123456789';
GRANT ALL ON *.* TO 'huupv'@'%';
FLUSH PRIVILEGES;

Create new a database.

create schema test_db;

The output terminal is as below:

vagrant@devopsroles:~/mysql-docker$ docker exec -it mysql1 mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 8.0.28-cluster MySQL Cluster Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE USER 'huupv'@'%' IDENTIFIED BY '123456789';
Query OK, 0 rows affected (0.02 sec)

mysql> GRANT ALL ON *.* TO 'huupv'@'%';
Query OK, 0 rows affected (0.11 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)

mysql> exit
Bye
vagrant@devopsroles:~/mysql-docker$ docker exec -it mysql2 mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 8.0.28-cluster MySQL Cluster Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE USER 'huupv'@'%' IDENTIFIED BY '123456789';
ERROR 1396 (HY000): Operation CREATE USER failed for 'huupv'@'%'
mysql> GRANT ALL ON *.* TO 'huupv'@'%';
Query OK, 0 rows affected (0.10 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> exit
Bye
vagrant@devopsroles:~/mysql-docker$

Login from my machine.

 mysql -h192.168.4.10 -uhuupv -p
 mysql -h192.168.4.11 -uhuupv -p

Via My Youtube

Conclusion

You have successfully deployed a MySQL cluster using Docker. You can now use the cluster for your applications or explore additional configuration options for MySQL clustering, such as replication and high availability. I hope will this your helpful. Thank you for reading the DevopsRoles page!

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!

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!