Category Archives: Docker

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

How to Deploy MongoDB as a Docker Container

Introduction

In this tutorial, How to Deploy MongoDB as a Docker container. MongoDB is a source-available cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas.

In today’s world of modern application development, containerization has become a popular approach for deploying and managing applications.

Install Docker

You need to install Docker on Ubuntu.

How to Deploy MongoDB as a Docker Container

First, We will pull version MongoDB as command below:

docker pull mongo:3.4.4

To create a volume for the database and retain data. The command line creates the volume as below:

docker volume create mongo_data

We will deploy it

docker run -d -v mongo_data:/data/db --name mymongoDB --net=host mongo:3.4.4 --bind_ip 127.0.0.1 --port 27000

You need to verify the deployment as command below:

docker ps -a

The container is running, How to access it?

docker exec -it mymongoDB mongo localhost:27000

If you need to stop the MongoDB container.

docker stop ID

If you need to start the MongoDB container.

docker start ID

Conclusion

You have successfully deployed MongoDB as a Docker container. This approach offers flexibility, scalability, and portability for your MongoDB deployments. With containerization, you can easily manage your database infrastructure and ensure consistency across different environments. I hope this will be helpful. Thank you for reading the DevopsRoles page!

Deploy Redmine Project Management using Docker

#Introduction

In this tutorial, How to Deploy Redmine Project Management using Docker Compose. Redmine is an Open Source project management you can install on your LAN or Cloud host.

You need to install Docker and Docker-Compose on Ubuntu.

Deploy Redmine Project Management

Create the Dockerfile

mkdir ~/redmine
cd ~/redmine
nano Dockerfile

paste the following content:

FROM redmine:5.0.3

RUN apt-get update

Save and close the file.

Create the docker-compose.yml file

nano docker-compose.yml

paste the following content:

version: '3.3'

services:

   postgres:

     image: postgres:10

     volumes:

       - ./storage/postgresql-data:/var/lib/postgresql/data

     environment:

       POSTGRES_PASSWORD: "POSTGRES12345"

       POSTGRES_DB: "redmine"

       PGDATA: "/var/lib/postgresql/data"

     restart: always

   redmine:

     build:

       context: .

     image: redmine:custom

     ports:

       - 80:3000

     volumes:

       - ./storage/docker_redmine-plugins:/usr/src/redmine/plugins

       - ./storage/docker_redmine-themes:/usr/src/redmine/public/themes

       - ./storage/docker_redmine-data:/usr/src/redmine/files

     environment:

       REDMINE_DB_POSTGRES: "postgres"

       REDMINE_DB_USERNAME: "postgres"

       REDMINE_DB_PASSWORD: "POSTGRES12345"

       REDMINE_DB_DATABASE: "redmine"

       REDMINE_SECRET_KEY_BASE: "…"

     restart: always

The deploy the container

docker-compose up -d

Access Redmine

Open your web browser to http://SERVER

Conclusion

You Deploy Redmine Project Management using Docker. I hope this will be helpful. Thank you for reading the DevopsRoles page!

Manage Docker Containers with Yacht

#Introduction

In this tutorial, How to Manage Docker Containers with Yacht. The yacht is GUI to Manage your Docker containers.

You can deploy, modify and manage containers with Yacht. I will set up Yacht on the Linux system.

Manage Docker Containers with Yacht

First, You need to Installed Docker on Linux here.

Pull the Yacht docker image

I will pull the Yacht docker image from DockerHub. Log in to the server using the root account.

sudo su -

Create volume to hold all of the Yacht data on the server.

docker volume create yacht

Docker will deploy the image as a container on your system with the command below

docker run -d -p 8000:8000 -v /var/run/docker.sock:/var/run/docker.sock -v yacht:/config selfhostedpro/yacht

After installing Yacht, you can access it via web UI in any browser.

http://IP-your-server:8000

Logging into Yacht

the default password and username to log into Yacht. admin@yacht.local/pass

Dashboard Yacht

View Applications

Manage volumes

Manage Network

Manage images by Yacht

Conclusion

You have Manage Docker Containers with Yacht. I hope this will be helpful. Thank you for reading the DevopsRoles page!

Set A Memory Limit For Docker Containers

#Introduction

In this tutorial, How to Set A Memory Limit For Docker Containers. Docker container defaults to running without any resource constraints.

In production, each container will set a memory limit to prevent runaway resource consumption.

How to Set A Memory Limit For Docker Containers

You set hard and soft memory limits on individual containers.

Hard memory limits

Hard limit on virtual memory, any worker exceeding the limit will be immediately killed without waiting for the end of the current request processing.

Soft memory limits

Maximum allowed virtual memory per worker.

How to setting hard memory limits

Set by docker run command with “-m” or “–memory” flag. For example, set value 2g

$ docker run --memory=2g devopsroles-app:latest

How to setting soft memory limits

Soft memory limits are set with the “–memory-reservation” flag. For example, set the value to 512m of reserved memory. It will always stop if usage exceeds 512MB.

$ docker run --memory=512m --memory-reservation=256m devopsroles:latest

setting Swap Memory

The “--memory-swap" flag controls the amount of swap space available in conjunction with the “–memory” flag. For example, Container has access to 1000MB of memory of which 512MB is physical RAM. The remaining 488MB is swap space stored on disk.

$ docker run --memory=512m --memory-swap=1000m devopsroles:latest

How to disable Out-Of-Memory process skills.

The result in the container stopping with the error code is 137. Use “–oom-kill-disable” with your docker run command to disable this behavior.

Conclusion

You have Set A Memory Limit For Docker Containers. I hope this will your helpful. Thank you for reading the DevopsRoles page!

Deploy the Latest Portainer Release

Portainer frequently releases updates. You can not simply login to your Portainer container upgrade button, in this tutorial, How to Deploy the Latest Portainer Release.

Backup Portainer container.

I’ll back up the current Portainer deployment.
Login with admin user and click Settings in the left navigation as in the picture below:

I will download the backup file to local storage and save a .tar.gz

Stop/Remove the Current Portainer Container

Login to the Container ID of Portainer and run the command below:

docker ps -a|grep portainer
docker stop ID
docker rm ID

Where ID is the ID of the Portainer container.

For example, The output terminal is as below:

Deploy the Latest Portainer Release

See install Portainer docker here. I used portainer_data for persistent storage.

First, You need to pull down the Portainer latest.

docker pull portainer/portainer-ce:latest

Deploy Portainer with the command line as below

docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce

Open a web browser and access to link: http://SERVER:9000

Restore a Backup for the Portainer container.

You need to deploy a fresh instance of Portainer with an empty data volume and choose the Restore Portainer from the backup option during setup. Click Select file and navigate to the .tar.gz file you downloaded earlier. After selecting the file, click Restore Portainer.

Conclusion

You have to deploy Portainer Docker. Please note that these steps provide a basic overview of deploying Portainer.

For a production environment, it’s essential to consider security measures and other best practices. It’s always recommended to consult Portainer’s official documentation for more detailed instructions specific to the latest release and any additional configuration options.

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

Docker deploy Joomla

Introduction

Docker has become an essential tool in the DevOps world, simplifying the deployment and management of applications. Using Docker to deploy Joomla – one of the most popular Content Management Systems (CMS) – offers significant advantages. In this article, we will guide you through each step to Docker deploy Joomla, helping you leverage the full potential of Docker for your Joomla project.

Requirements

  • Have installed Docker on your system.
  • The host OS is Ubuntu Server.

To deploy Joomla using Docker, you’ll need to follow these steps:

Docker Joomla

Create a new Docker joomla network

docker network create joomla-network

Check Joomla network is created.

Next, pull Joomla and MySQL images as command below:

docker pull mysql:5.7
docker pull joomla

Create the MySQL volume

docker volume create mysql-data

Deploy the database

docker run -d --name joomladb  -v mysql-data:/var/lib/mysql --network joomla-network -e "MYSQL_ROOT_PASSWORD=PWORD_MYSQL" -e MYSQL_USER=joomla -e "MYSQL_PASSWORD=PWORD_MYSQL" -e "MYSQL_DATABASE=joomla" mysql:5.7

Where PWORD_MYSQL is a unique/strong password

How to deploy Joomla

create a volume to hold the Joomla data as command below:

docker volume create joomla-data
docker run -d --name joomla -p 80:80 -v joomla-data:/var/www/html --network joomla-network -e JOOMLA_DB_HOST=joomladb -e JOOMLA_DB_USER=joomla -e JOOMLA_DB_PASSWORD=PWORD_MYSQL joomla

Access the web-based installer

Open the web browser to http://SERVER:PORT, where SERVER is either the IP address or domain of the hosting server, and PORT is the external port.

Follow the Joomla setup wizard to configure your Joomla instance.

Via Youtube

Conclusion

Deploying Joomla with Docker not only simplifies the installation and configuration process but also enhances the management and scalability of your application. With the detailed steps provided in this guide, you can confidently deploy and manage Joomla on the Docker platform. Using Docker saves time and improves the performance and reliability of your system. Start today to experience the benefits Docker brings to your Joomla project. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Create docker secret and deploy a service

#Introduction

In this tutorial, How to create docker secret and deploy a service. Docker secrets encrypt things like passwords and certificates within a service and container.

Requirements

How to create a secret

We’ll use the command printf and pipe the output to the docker command to create a secret called test_secret. As command below:

printf "My secret secret" | docker secret create test_secret -

To check the result with the command below

docker secret ls

The output as below:

vagrant@controller:~$ docker secret ls
ID                          NAME          DRIVER    CREATED          UPDATED
txrthzah1vnl4kyrh282j39ft   test_secret             24 seconds ago   24 seconds ago

create a service that uses the secret

To deploy that service, using the test_secret secret, the command looks something like this:

docker service  create --name redis --secret test_secret redis:alpine

Verify the service is running as the command below

docker service ps redis

The output is as below:

vagrant@controller:~$ docker service ps redis
ID             NAME      IMAGE          NODE         DESIRED STATE   CURRENT STATE            ERROR     PORTS
y6249s3xftxa   redis.1   redis:alpine   controller   Running         Running 33 seconds ago   

Verify the service has access to the secret as below

docker container exec $(docker ps --filter name=redis -q) ls -l /run/secrets

The output is as below:

vagrant@controller:~$ docker container exec $(docker ps --filter name=redis -q) ls -l /run/secrets
total 4
-r--r--r--    1 root     root            16 May 30 13:50 test_secret

Finally, you can view the contents of the secret with the command:

docker container exec $(docker ps --filter name=redis -q) cat /run/secrets/test_secret

The output is as below:

My secret secret

If you commit the container, the secret is no longer available.

docker commit $(docker ps --filter name=redis -q) committed_redis

Verify the secret is no longer available with the command below:

docker run --rm -it committed_redis cat /run/secrets/test_secret

You can then remove access to the secret with the command:

docker service update --secret-rm test_secret redis

Conclusion

You have to Create docker secret and deploy a service. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Elastic APM Tool for Application Performance Monitoring

#Introduction

Elastic APM helps you monitor overall application health and performance. It is part of the Elastic Stack, which includes Elasticsearch, Logstash, and Kibana.

Elastic APM allows you to track and analyze the performance metrics of your applications, identify bottlenecks, and troubleshoot issues.

Prerequisites

Elastic APM Tool

How to integrate the application with APM tool: elasticsearch, kibana, and apm-server

We will create a docker-compose file with the content below:

nano docker-compose.yml

The content file as below:

version: '3'
services:
      elasticsearch:
        image: docker.elastic.co/elasticsearch/elasticsearch:6.6.1
        ports:
          - "9200:9200"
      kibana:
        image: docker.elastic.co/kibana/kibana:6.6.1
        ports:
          - "5601:5601"
        depends_on:
          - elasticsearch
      apm-server:
          image: docker.elastic.co/apm/apm-server:6.6.1
          environment:
            - output.elasticsearch.hosts=["elasticsearch:9200"]
          ports:
            - "8200:8200"
          depends_on:
            - elasticsearch

Save and close that file.

Running the APM tool

docker-compose up -d

The result is the picture below:

Now, We will start the application with the javaagent and point to apm-server URL

java -javaagent:/<path-to-jar>/elastic-apm-agent-<version>.jar \
     -Delastic.apm.service_name=my-application \
     -Delastic.apm.server_url=http://localhost:8200 \
     -Delastic.apm.secret_token= \
     -Delastic.apm.application_packages=<base package> \
     -jar <jar name>.jar

Note: apm.application_packages → package where the main class is present

Configuration steps on Kibana

  • Goto: http://localhost:5601 (http://localhost:5601/)
  • Click on Add APM
  • Scroll down and click on Check APM Server Status
  • Scroll down and click on Check agent status
  • Click on Load Kibana objects
  • Launch APM

APM is now ready and integrated with the service.

Conclusion

You have Elastic APM Tool for Application Performance Monitoring.

Elastic APM is a comprehensive tool for monitoring the performance of your applications, providing deep insights into transaction traces, metrics, errors, and code-level details. It helps you identify performance issues, optimize application performance, and deliver a better user experience.

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

Docker Swarm cheat sheet: Essential Commands and Tips

Introduction

Here’s a Docker Swarm cheat sheet to help you with common commands and operations:

Docker Swarm is a powerful tool for container management and application orchestration. For those working in the DevOps field, mastering Docker Swarm commands and techniques is essential for effective system deployment and management.

This article provides a detailed cheat sheet, compiling important commands and useful tips, to help you quickly master Docker Swarm and optimize your workflow.

The Docker swarm cheat sheet

Docker swarm Management

Set up master

docker swarm init --advertise-addr <ip>

How to Force the Manager on a Broken Cluster

docker swarm init --force-new-cluster -advertise-addr <ip>

Enable auto-lock

docker swarm init –autolock

Get a token to join the workers

docker swarm join-token worker

Get a token to join the new manager

docker swarm join-token manager

Join the host as a worker

docker swarm join <server> worker

Have a node leave a swarm

docker swarm leave

Unlock a manager host after the docker

docker swarm unlock

Print key needed for ‘unlock’

docker swarm unlock-key

Print swarm node list

docker node ls

Docker Service Management

Create a new service:

docker service create <options> <image> <command>

List the services running in a swarm

docker service ls

Inspect a service:

docker service inspect <service-id>

Scale a service (increase or decrease replicas)

docker service scale <service-id>=<replica-count>

Update a service:

docker service update <options> <service-id>

Remove a service:

docker service rm <service-id>

List the tasks of the service_name

docker service ps service_name

list running (active) tasks for a given service

docker service ps --filter desired-state=running <service id|name>

print console log of a service

docker service logs --follow <service id|name>

Promote a worker node to the manager

docker node promote node_name

The output terminal Promote a worker node to the manager as below

vagrant@controller:~$ docker node ls
ID                            HOSTNAME     STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
9b2211c8l1bmhu3h2ij3kthxv *   controller   Ready     Active         Leader           20.10.14
0j0pslqf4g6xkki8ajydvc123     node1        Ready     Active                          20.10.14
f4cxubqg0wqdxsaj8pe4qsqlg     node2        Ready     Active                          20.10.14

vagrant@controller:~$ docker node promote f4cxubqg0wqdxsaj8pe4qsqlg
Node f4cxubqg0wqdxsaj8pe4qsqlg promoted to a manager in the swarm.

vagrant@controller:~$ docker node ls
ID                            HOSTNAME     STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
9b2211c8l1bmhu3h2ij3kthxv *   controller   Ready     Active         Leader           20.10.14
0j0pslqf4g6xkki8ajydvc123     node1        Ready     Active                          20.10.14
f4cxubqg0wqdxsaj8pe4qsqlg     node2        Ready     Active         Reachable        20.10.14

Docker Stack Management

List running swarms

docker stack ls

Deploy a stack using a Compose file:

docker stack deploy --compose-file <compose-file> <stack-name>

Inspect a stack:

docker stack inspect <stack-name>

List services in a stack:

docker stack services <stack-name>

List containers in a stack:

docker stack ps <stack-name>

Remove a stack:

docker stack rm <stack-name>

Conclusion

You now have the Docker Swarm cheat sheet, which includes some of the most essential commands used in Docker Swarm.

For a more comprehensive list of options and additional commands, please refer to the official Docker documentation:

For a more detailed list of options and additional commands, you can refer to the official Docker documentation. I hope you find this helpful. Thank you for visiting the DevopsRoles page!

Deploying Services to a Docker Swarm Cluster

Introduction

In this tutorial, How to Deploy Services to a Docker Swarm Cluster. First, You need to install the Docker swarm cluster here. In today’s world of distributed systems, containerization has become a popular choice for deploying and managing applications.

Docker Swarm, a native clustering and orchestration solution for Docker, allows you to create a swarm of Docker nodes that work together as a cluster.

In this blog post, we will explore the steps to deploy a service to a Docker Swarm cluster and take advantage of its powerful features for managing containerized applications.

Deploying Services to a Docker Swarm Cluster

The simple, I will deploy the NGINX container service.

Log into Controller. Run the following command.

docker service create --name nginx_test nginx

To check the service status as command below

vagrant@controller:~$ docker service ls
ID             NAME         MODE         REPLICAS   IMAGE          PORTS
44sp9ig3k65o   nginx_test   replicated   1/1        nginx:latest

We will deploy that service to all three nodes as commanded below

docker service create --replicas 3 --name nginx3nodes nginx

The result is Deploy service to the swarm as the picture below

You want to scale the service to all five nodes.

docker service scale nginx3nodes=5

We deploy Portainer on the controller to easily manage the swarm.

docker run -d -p 8000:8000 -p 9443:9443 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce

Open the browser, and go to http://SERVER:9443 (Where SERVER is the IP address of the server). you should see Swarm listed in the left navigation

Swarm on portainer

Conclusion

You have to Deploy the service to the swarm. Docker Swarm will take care of scheduling the service across the Swarm nodes and managing its lifecycle. Docker Swarm simplifies the management and scaling of containerized applications, providing fault tolerance and high availability. By following the steps outlined in this blog post, you can easily deploy your services to a Docker Swarm cluster and take advantage of its powerful orchestration capabilities. I hope will this your helpful. Thank you for reading the DevopsRoles page!