Category Archives: Docker

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

Docker pull issues TLS handshake timeout

#Introduction

Today, I have installed Docker on Vagrant Environment. Docker pull issues TLS handshake timeout as code follows

[vagrant@localhost ~]$ sudo docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
35807b77a593: Extracting [==========================================>        ]  24.18MB/28.57MB
error pulling image configuration: Get "https://registry-1.docker.io/v2/library/ubuntu/blobs/sha256:fb52e22af1b01869e23e75089c368a1130fa538946d0411d47f964f8b1076180": net/http: TLS handshake timeout

My Lab

  • Host: Windows 10
  • Vagrant box Ubuntu
  • Docker installed on Vagrant VM

How do fixed it

I just reloaded the daemon and restarted the docker service. It solved this issue. You can use the below commands.

$ sudo systemctl daemon-reload
$ sudo systemctl restart docker
$ sudo systemctl status docker

Open Network Connections on Windows 10

Set DNS google for VirtualBox Host-Only Network

  • DNS1: 8.8.8.8
  • DNS2: 8.8.4.4

Turn IPv6 off

The result, Docker pull ubuntu

[vagrant@localhost ~]$ sudo docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
35807b77a593: Already exists
Digest: sha256:9d6a8699fb5c9c39cf08a0871bd6219f0400981c570894cd8cbea30d3424a31f
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest
[vagrant@localhost ~]$

Conclusion

You have fixed Error Pulling Image Configuration: Get Https://Xxxx : Net/Http: TLS Handshake Timeout. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Get a Docker Containers IP Address from the Host

Introduction

Docker containers are isolated. How do you need to know each container’s IP address? Docker networking is a little complicated. Containers launched by default in the “bridge network” and allowed to communicate with another container directly. Containers added to non-default networks will be able to access each other through their alias

My example

Create a new network is devopsroles, run containers, and access the other containers using an alias as below:

docker network create devopsroles
docker run --net devopsroles  --name nginx -d nginx
docker run  --name mongodb -d mongo
docker network connect devopsroles  --alias mongohost mongodb

Get a Docker Containers IP Address from the Host

How to get IP address Docker containers from the Host OS.

docker ps
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' name_or_id

The output terminal is as follows

[vagrant@localhost ~]$ docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS              PORTS       NAMES
fc0c94f5ef9d   mongo     "docker-entrypoint.s…"   3 minutes ago   Up 3 minutes        27017/tcp   mongodb
a2b21fffc9d8   nginx     "/docker-entrypoint.…"   6 hours ago     Up About a minute   80/tcp      nginx
[vagrant@localhost ~]$ docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' fc0c94f5ef9d
172.17.0.2172.18.0.2
[vagrant@localhost ~]$ docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' a2b21fffc9d8
172.18.0.3
[vagrant@localhost ~]$

You can use the docker network inspect command to print all containers in the given network.

docker network inspect bridge -f '{{json .Containers}}'

Get network config from the containers

docker exec -it container_name_Or_ID ip a

Conclusion

You have to Get a Docker Containers IP Address from the Host. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Docker compose run Grafana 8

Introduction

In this tutorial, how to run Grafana version 8 using Docker-compose. Now, we will use Docker compose run Grafana version 8.

Docker compose run Grafana

Grafana Docker container

I will create a folder for Grafana on the Host Ubuntu OS.

sudo mkdir -p /home/huupv/docker/grafana/data
sudo mkdir -p /home/huupv/docker/compose-files/Grafana
cd /home/huupv/docker/compose-files/Grafana

Create a new docker-compose.yml file with the following

version: "3.5"

services:
  grafana8:
    image: grafana/grafana:latest
    network_mode: "bridge"
    container_name: grafana8
	# user: "1000" # needs to be `id -u` // alternatively chown the grafana/data dir to 472:472
    volumes:
      - /home/huupv/docker/grafana/data:/var/lib/grafana
    ports:
      - "3000:3000"
    restart: always

The change port if you want.

The deploy Grafana

sudo docker-compose up -d

Your open browser the following URL: http://yourIP:3000

To log in for the first time, use the admin:admin username and password combination.

Login the success

The during start Grafana error [fixed it]

Code Error Grafana

huupv@ubuntu:~/docker/compose-files/grafana$ sudo docker ps
CONTAINER ID   IMAGE                    COMMAND                  CREATED          STATUS                         PORTS                                                                                        NAMES
4e1f6f81da09   grafana/grafana:latest   "/run.sh"                27 seconds ago   Restarting (1) 3 seconds ago                                                                                                grafana8
304a31a535c5   telegraf:latest          "/entrypoint.sh tele…"   3 hours ago      Up 2 hours                     0.0.0.0:8092->8092/tcp, 8092/udp, 0.0.0.0:8094->8094/tcp, 8125/udp, 0.0.0.0:8125->8125/tcp   telegraf
5909e05dd5bd   influxdb:latest          "/entrypoint.sh infl…"   3 hours ago      Up 2 hours                     0.0.0.0:8086->8086/tcp                                                                       influxdb2
huupv@ubuntu:~/docker/compose-files/grafana$ sudo docker logs grafana8
GF_PATHS_DATA='/var/lib/grafana' is not writable.
You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migrate-to-v51-or-later
mkdir: can't create directory '/var/lib/grafana/plugins': Permission denied
GF_PATHS_DATA='/var/lib/grafana' is not writable.
You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migrate-to-v51-or-later
mkdir: can't create directory '/var/lib/grafana/plugins': Permission denied
GF_PATHS_DATA='/var/lib/grafana' is not writable.
You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migrate-to-v51-or-later
mkdir: can't create directory '/var/lib/grafana/plugins': Permission denied
GF_PATHS_DATA='/var/lib/grafana' is not writable.
You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migrate-to-v51-or-later
mkdir: can't create directory '/var/lib/grafana/plugins': Permission denied
GF_PATHS_DATA='/var/lib/grafana' is not writable.
You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migrate-to-v51-or-later
mkdir: can't create directory '/var/lib/grafana/plugins': Permission denied
GF_PATHS_DATA='/var/lib/grafana' is not writable.
You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migrate-to-v51-or-later
mkdir: can't create directory '/var/lib/grafana/plugins': Permission denied
GF_PATHS_DATA='/var/lib/grafana' is not writable.
You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migrate-to-v51-or-later
mkdir: can't create directory '/var/lib/grafana/plugins': Permission denied
GF_PATHS_DATA='/var/lib/grafana' is not writable.
You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migrate-to-v51-or-later
mkdir: can't create directory '/var/lib/grafana/plugins': Permission denied
GF_PATHS_DATA='/var/lib/grafana' is not writable.
You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migrate-to-v51-or-later
mkdir: can't create directory '/var/lib/grafana/plugins': Permission denied

Fixed it

huupv@ubuntu:~/docker/compose-files/grafana$ id -u
1001

# user: "1000" # needs to be `id -u` // alternatively chown the grafana/data dir to 472:472


huupv@ubuntu:~/docker/compose-files/grafana$ sudo chown 472:472 /home/huupv/docker/grafana/data

Result, Docker compose run Grafana 8.

huupv@ubuntu:~/docker/compose-files/grafana$ sudo docker ps
CONTAINER ID   IMAGE                    COMMAND                  CREATED         STATUS                          PORTS                                                                                        NAMES
4e1f6f81da09   grafana/grafana:latest   "/run.sh"                5 minutes ago   Restarting (1) 50 seconds ago                                                                                                grafana8
304a31a535c5   telegraf:latest          "/entrypoint.sh tele…"   3 hours ago     Up 2 hours                      0.0.0.0:8092->8092/tcp, 8092/udp, 0.0.0.0:8094->8094/tcp, 8125/udp, 0.0.0.0:8125->8125/tcp   telegraf
5909e05dd5bd   influxdb:latest          "/entrypoint.sh infl…"   3 hours ago     Up 2 hours                      0.0.0.0:8086->8086/tcp                                                                       influxdb2
huupv@ubuntu:~/docker/compose-files/grafana$ sudo docker restart grafana8
grafana8

huupv@ubuntu:~/docker/compose-files/grafana$ sudo chown 472:472 /home/huupv/docker/grafana/data
huupv@ubuntu:~/docker/compose-files/grafana$ ls -ld  /home/huupv/docker/grafana/data
drwxrwxr-x 2 472 472 4096 Aug  8 21:23 /home/huupv/docker/grafana/data

huupv@ubuntu:~$ sudo docker ps
CONTAINER ID   IMAGE                    COMMAND                  CREATED       STATUS       PORTS                                                                                        NAMES
c4d40e897c36   grafana/grafana:latest   "/run.sh"                2 hours ago   Up 2 hours   0.0.0.0:3000->3000/tcp                                                                       grafana8
304a31a535c5   telegraf:latest          "/entrypoint.sh tele…"   5 hours ago   Up 4 hours   0.0.0.0:8092->8092/tcp, 8092/udp, 0.0.0.0:8094->8094/tcp, 8125/udp, 0.0.0.0:8125->8125/tcp   telegraf
5909e05dd5bd   influxdb:latest          "/entrypoint.sh infl…"   5 hours ago   Up 4 hours   0.0.0.0:8086->8086/tcp                                                                       influxdb2
huupv@ubuntu:~$

Conclusion

Using Docker Compose, you’ve successfully launched Grafana 8. This tutorial aims to be a helpful resource for your monitoring setup. Thank you for choosing DevopsRoles for guidance. We appreciate your engagement and are here to support your continued learning in Docker and software deployment.

Docker container image for rocky Linux

#Introduction

How to use Rocky Linux as a Docker container image. In this tutorial, how to get it, deploy it. Now, We will use the Docker container image for rocky Linux.

Rocky Linux to replace Centos.

You will need a VM with the Docker engine installed and running.

Docker container image for rocky Linux

pull down the Rocky Linux image

Open a terminal window. The run command is below

docker pull rockylinux/rockylinux

The docker image will be saved to your local repository and used it. You can verify it

docker images

create a container from the Rocky Linux image

Create a container devopsroles and deploy it in detached mode as the command below

docker run -it --name devopsroles -d rockylinux/rockylinux

Access to the container devopsroles

docker exec -it --user root devopsroles /bin/bash

You can destroy the Rocky Linux container as command below

docker ps -a
docker stop Container_ID
docker rm Container_ID

Conclusion

You have used Rocky Linux as a Docker container image. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Create Docker Image of a .NET Web API

Introduction

Docker helps you to run software projects without the need to set up complex development environments.

In this tutorial, How to Create Docker Image of a .NET Web API. You can use Docker image to run the backend from any PC that has Docker installed and front-end web project interact with the API.

Create a .NET Web API

I will create a project named “exdockerapi” use the dotnet CLI with the following command:

dotnet new webapi -o aspdockerapi

If you don’t have .NET 5 installed on your PC. Please, you can download it here.

Now, you can go into the project exdockerapi is created, and run the web API.

cd exdockerapi
dotnet run

By default, the application is on port 5001.

Create Docker Image of a .NET Web API

I will create a new file Dockerfile with the following command:

touch Dockerfile

Now, we will copy and paste the code below into Dockerfile.

FROM mcr.microsoft.com/dotnet/aspnet:5.0-focal AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:5.0-focal AS build
WORKDIR /src
COPY ["exdockerapi.csproj", "./"]
RUN dotnet restore "./exdockerapi.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "exdockerapi.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "exdockerapi.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "exdockerapi.dll"]

How to building the Docker Image

The simply build the Docker image based on the Dockerfile with the following command:

docker build -t dockerwebapiex -f Dockerfile .

To check Docker image is dockerwebapiex with the following command:

docker images | grep dockerwebapiex

Run the Docker Image

Use the following command.

docker run -ti --rm -p 8080:80 dockerwebapiex
  • The -ti option specifies that the image should be run in an interactive terminal mode
  • –rm specifies that the container should be removed immediately after it exits.

Conclusion

You have installed Create Docker Image of a .NET Web API. I hope will this your helpful. Thank you for reading the DevopsRoles page!

How to deploy OpenProject platform as a Docker Container

#Introduction

In this tutorial, How to deploy OpenProject platform as a Docker Container.

OpenProject is an outstanding platform for project management. It is manage meetings, control project budgets, run reports on your projects, communicate with a project team, etc.

Deploy OpenProject platform as a Docker Container

Install Docker and Docker-Compose

I will this deployment on Ubuntu Server.

sudo apt-get install docker.io -y
sudo usermod -aG docker $USER
sudo curl -L "https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

Check version after finished install.

root@DevopsRoles:~# docker --version
Docker version 20.10.2, build 20.10.2-0ubuntu2
root@DevopsRoles:~# docker-compose --version
docker-compose version 1.23.1, build b02f1306

Deploy OpenProject with Docker Compose

git clone https://github.com/opf/openproject-deploy --depth=1 --branch=stable/11 myopenproject
cd myopenproject/compose
docker-compose pull # Make sure to update docker images.
docker-compose up -d # You need to wait a few minutes.

For example, The output terminal is as below:

root@DevopsRoles:~# git clone https://github.com/opf/openproject-deploy --depth=1 --branch=stable/11 myopenproject
Cloning into 'myopenproject'...
remote: Enumerating objects: 7, done.
remote: Counting objects: 100% (7/7), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 7 (delta 0), reused 2 (delta 0), pack-reused 0
Receiving objects: 100% (7/7), done.
root@DevopsRoles:~# cd myopenproject/compose
root@DevopsRoles:~/myopenproject/compose# docker-compose pull
Pulling db     ... done
Pulling cache  ... done
Pulling seeder ... done
Pulling cron   ... done
Pulling worker ... done
Pulling web    ... done
Pulling proxy  ... done
root@DevopsRoles:~/myopenproject/compose# docker-compose up -d
Creating network "compose_backend" with the default driver
Creating network "compose_frontend" with the default driver
Creating volume "compose_pgdata" with default driver
Creating volume "compose_opdata" with default driver
Creating compose_seeder_1_f0f0cb90c947 ... done
Creating compose_cache_1_e6fe61ccd342  ... done
Creating compose_db_1_17392590a82e     ... done
Creating compose_cron_1_f15f9d68fc11   ... done
Creating compose_web_1_ce68c823fc5f    ... done
Creating compose_worker_1_a9c88ca2f672 ... done
Creating compose_proxy_1_c7c5f08e77e8  ... done
root@DevopsRoles:~/myopenproject/compose#
root@DevopsRoles:~/myopenproject/compose# docker ps
CONTAINER ID   IMAGE                      COMMAND                  CREATED          STATUS          PORTS                            NAMES
9aa1fe05f737   openproject/community:11   "./docker/prod/entry…"   40 seconds ago   Up 35 seconds   5432/tcp, 0.0.0.0:8080->80/tcp   compose_proxy_1_5fdbbaa63ec5
2df1b233a515   openproject/community:11   "./docker/prod/entry…"   42 seconds ago   Up 39 seconds   80/tcp, 5432/tcp                 compose_worker_1_6db9f1adb68b
e1b6878e9e32   openproject/community:11   "./docker/prod/entry…"   42 seconds ago   Up 39 seconds   80/tcp, 5432/tcp                 compose_web_1_544e288b78ff
ef3b645bc783   openproject/community:11   "./docker/prod/entry…"   42 seconds ago   Up 39 seconds   80/tcp, 5432/tcp                 compose_cron_1_db11c0e207d9
0dad3d1c28d1   postgres:10                "docker-entrypoint.s…"   46 seconds ago   Up 41 seconds   5432/tcp                         compose_db_1_31484339d5bc
1cd386cca514   memcached                  "docker-entrypoint.s…"   46 seconds ago   Up 41 seconds   11211/tcp                        compose_cache_1_6b9f381e6e82
13f9ad2a8cfa   openproject/community:11   "./docker/prod/entry…"   46 seconds ago   Up 41 seconds   80/tcp, 5432/tcp                 compose_seeder_1_f88dde804cb4

The result is openproject docker the picture below:

How to deploy with docker

sudo mkdir -p /var/lib/myopenproject/{pgdata,assets}
head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32 ; echo '' # The random key generated for SECRET_KEY_BASE variable.

Deploy the OpenProject containers with the command:

docker run -d -p 8080:80 --name myopenproject -e SECRET_KEY_BASE=secret -v /var/lib/myopenproject/pgdata:/var/myopenproject/pgdata -v /var/lib/myopenproject/assets:/var/myopenproject/assets openproject/community:11

The output terminal is as below:

root@DevopsRoles:~/myopenproject/compose# head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32 ; echo ''
HgRwijSjJXYBHRl8MSPfm7oiYd0F5hmK
root@DevopsRoles:~/myopenproject/compose# docker run -d -p 8080:80 --name myopenproject -e SECRET_KEY_BASE=HgRwijSjJXYBHRl8MSPfm7oiYd0F5hmK -v /var/lib/myopenproject/pgdata:/var/myopenproject/pgdata -v /var/lib/myopenproject/assets:/var/myopenproject/assets openproject/community:11
24c5f3fb9b560f4eca821555a50d8cab8ef7b3e38616071db9083ed2784219fe
root@DevopsRoles:~/myopenproject/compose# docker ps
CONTAINER ID   IMAGE                      COMMAND                  CREATED         STATUS         PORTS                            NAMES
24c5f3fb9b56   openproject/community:11   "./docker/prod/entry…"   5 seconds ago   Up 4 seconds   5432/tcp, 0.0.0.0:8080->80/tcp   myopenproject
root@DevopsRoles:~/myopenproject/compose# netstat -nplt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:38701         0.0.0.0:*               LISTEN      15247/containerd
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      19208/docker-proxy
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      599/systemd-resolve
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1091/sshd: /usr/sbi
tcp6       0      0 :::22                   :::*                    LISTEN      1091/sshd: /usr/sbi

Conclusion

You have to deploy the OpenProject platform as a Docker Container. I hope will this your helpful. Thank you for reading the DevopsRoles page! deploy OpenProject.

Install Portainer Docker Web GUI on Linux

#Introduction

In this tutorial, How to Install Portainer Docker Web GUI on Linux. Portainer is a web-based management UI for Docker hosts.

Install Portainer Docker

I have installed docker on My computer. First, Create a Docker volume portainer_data

$ docker volume create portainer_data
Or,
$ sudo docker volume create portainer_data

Example:

[root@DockerServer ~]# docker volume create portainer_data
portainer_data
[root@DockerServer ~]# docker volume ls
DRIVER              VOLUME NAME
local               portainer_data

Create a Portainer Docker container.

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

-d – the container runs in the background
-p 8000: 8000 – Releases the corresponding ports on the host system of Docker
–Name = Portainer – To easily identify the container created for Portainer Docker
–Restart = always – The container is always restarted here.
-v /var/run/docker.sock:/var/run/docker.sock – Specifies that the container is allowed to access the Docker socket storage.
-v portainer_data: / data – Created storage “portainer_data” to the storage folder “/data” within the container.

Example:

[root@DockerServer ~]# 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
Unable to find image 'portainer/portainer-ce:latest' locally
Trying to pull repository docker.io/portainer/portainer-ce ...
latest: Pulling from docker.io/portainer/portainer-ce
94cfa856b2b1: Pull complete
49d59ee0881a: Pull complete
527b866940d5: Pull complete
Digest: sha256:5064d8414091c175c55ef6f8744da1210819388c2136273b4607a629b7d93358
Status: Downloaded newer image for docker.io/portainer/portainer-ce:latest
531acdb49696ad5206043915b157bc63bcd0783149485d17bfdd18993a72535a
[root@DockerServer ~]# docker ps
CONTAINER ID        IMAGE                    COMMAND             CREATED             STATUS              PORTS                                            NAMES
531acdb49696        portainer/portainer-ce   "/portainer"        11 seconds ago      Up 10 seconds       0.0.0.0:8000->8000/tcp, 0.0.0.0:9000->9000/tcp   portainer

Accessing Portainer Docker Web Interface

Check Portainer is running in the background as a container on Docker.

[root@DockerServer ~]# docker ps
CONTAINER ID        IMAGE                    COMMAND             CREATED             STATUS              PORTS                                            NAMES
531acdb49696        portainer/portainer-ce   "/portainer"        11 seconds ago      Up 10 seconds       0.0.0.0:8000->8000/tcp, 0.0.0.0:9000->9000/tcp   portainer

Open a web browser http://192.168.3.6:9000

Create Administrator account

Connect Portainer to the container environment

Web Interface

Conclusion

You have to install Portainer Docker Web GUI on Linux. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Docker Container Essentials: A Comprehensive Handbook for Efficient Application Deployment

Introduction

You will be learning about container manipulation basics in detail. Container manipulation you will be performing every single day. You can visit the official refer here for the Docker command Line. Now, We write a Docker container handbook.

What is a docker container?

its core is a self-contained and lightweight entity that wraps up an application along with all its dependencies. This encapsulation ensures that the application runs consistently across different computing environments. It operates on the principle of containerization, with Docker being a widely used platform for implementing this concept.

One of the key advantages of Docker containers lies in their portability. Applications packaged within containers can seamlessly transition between development, testing, and production environments. This consistent behavior across various platforms simplifies the deployment process and minimizes compatibility challenges.

Containers leverage the host system’s kernel, resulting in efficiency gains by sharing resources and enabling quick startup times. These containers are built from images, which are compact and versioned packages containing the application and its required components. Docker containers are not just isolated units; they also facilitate streamlined software development, testing, and deployment processes.

Run a Container

The syntax of this command is below for version 1.13:

docker run <image name>

In the new version, The syntax of this command is as below:

docker <object> <command> <options>

In this syntax:

  • object can be a container, image, network, or volume object.
  • command is the run command.
  • options can be any valid parameter that can override the default behavior of the command. example, –publish option for port mapping.

Now, for this syntax, the run command is as follows:

docker container run <image name>

The “image name” can be any image from an online registry or your local system.

For example, To run a container using the image as my terminal below:

docker container run --publish 8080:80 nginx

Publish a Port

The host system doesn’t know inside a container. How to outside access inside a container. The syntax, The Publish a port a container.

--publish <host port>:<container port>

Use Detached Mode

To a container running in the background, you can use the –detach option with the run command.

docker container run --detach --publish 8080:80 nginx

List Containers

You will list out containers that are currently running.

docker container ls

List all out containers.

docker container ls --all

Stop or Kill a Running Container

The syntax Stop or kill a Container

docker container stop <container identifier>
docker container kill <container identifier>
  • <container identifier>: can either be the id or the name of the container.

How to restart a Container

Restarting a container that has been previously stopped or killed

docker container start <container identifier>

Rebooting a running container.

docker container restart <container identifier>

Rename a Container

By default, every container has two identifiers

  • CONTAINER ID
  • NAME

Using the –name option defined Naming a container

docker container run --detach --publish 8888:80 --name nginx-container nginx

The syntax renames a container

docker container rename <container identifier> <new name>

Remove Dangling Containers

Find out containers are not running, use the command “docker container ls –all

The syntax removes Dangling Containers

docker container rm <container identifier>

Execute Commands Inside a Container

docker run name-of-image uname -a

In conclusion, the Docker container handbook provides a comprehensive understanding of the principles and benefits of containerization. I trust that this resource proves to be valuable for your endeavors in deploying and managing applications using Docker containers. The versatility, consistency, and efficiency offered by containerization, as highlighted in the handbook, are crucial aspects that enhance the software development and deployment lifecycle. If you have any further questions or seek additional insights, feel free to explore more on the DevopsRoles page! Thank you for taking the time to read and engage with the content. Best of luck with your Docker container journey in the realm of DevOps!

DevOps Use Docker to hands-on Ansible

Introduction

In this tutorial, I demonstrate how to use Docker for hands-on Ansible automation. Learn how to leverage Docker in a DevOps workflow and streamline configuration management with Ansible. A practical guide for DevOps professionals and beginners.

DevOps Use Docker

My Laptop Setup:

  • Operating System: Windows 10
  • Tools: Docker and Docker Compose

By using Docker to create one Ansible container and Server01 and Server02 containers. From Ansible command is executed in Ansible container to Two target container.

Let go use Docker to hands-on Ansible

Directory Structure

├── Docker
│   ├── Ansible_Control_node
│   │   └── Dockerfile      
│   └── Target_Server
│       └── Dockerfile      
├── docker-compose.yml      
├── hosts            
└── playbook.yml

Explain File and Directory Structure

I will not explain it to Docker because it is out of this post. The basic file of Ansible.

  1. hosts the file describes the target server running
  2. playbook.yml the file I will create a new file is devopsroles.txt for two targets.

The content of files as below

docker-compose.yml file

version: '3'
services:
  ansible:
    container_name: ansible
    build: ./Ansible_Control_node
    tty: true
    working_dir: "/var/data"
    volumes:
      - .:/var/data

  server01:
    container_name: server01
    build: ./Target_Server
    tty: true
  server02:
    container_name: server02
    build: ./Target_Server
    tty: true

playbook.yml file

- hosts: target
  tasks:
  - name: "Create new file devopsroles.txt"
    shell: |
        touch devopsroles.txt

hosts file

[target]
server01
server02

Ansible_Control_node/Dockerfile file

FROM centos
ENV ANSIBLE_HOST_KEY_CHECKING False
RUN yum install epel-release -y && \
    yum update -y && \
        yum install -y openssh-server openssh-clients net-tools && \
    yum install -y ansible
CMD /bin/bash

Target_Server/Dockerfile file

# Centos image latest
FROM centos:latest

# Install OpenSSh server with yum
RUN yum -y install openssh-server openssh-clients

# Created because public key is required when starting sshd
RUN ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
RUN ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa

# Allow login as root
RUN sed -ri 's/^#PermitEmptyPasswords no/PermitEmptyPasswords yes/' /etc/ssh/sshd_config

# Specify root password
RUN echo "root:" | chpasswd

EXPOSE 22

# Start sshd
CMD ["/usr/sbin/sshd", "-D"]

Start Ansible and two target containers.

docker-compose up -d

Connect to Ansible container

docker exec -it ansible /bin/bash

SSH connection without password from Ansible container to Two target container.

	ssh server01
	exit
	ssh server02
	exit

Run the Ansible command.

ansible-playbook -i hosts playbook.yml

Execution result of Ansible

Link Youtube

Conclusion

Using Docker with Ansible in DevOps simplifies automation and improves efficiency. By integrating these powerful tools, you can streamline your deployment and configuration management processes. Thank you for visiting the DevOpsRoles.com page.

How to use Docker-compose Build SonarQube

In this tutorial, How to Docker-compose Build SonarQube.

Docker-compose Build SonarQube

Build SonarQube with Docker-compose

  • WebApp: Create Mysql with Docker-compose
  • SonarQube: Create Mysql with Docker-compose
  • And Launch SonarQube with Docker-compose

Folder Structure for SonarQube

[vagrant@localhost ~]$ tree docker
 docker
 ├── docker-compose.yml
 ├── mysql
 │   ├── conf
 │   │   └── custom.cnf
 │   └── init
 │       ├── 1_create_db.sql
 │       ├── 2_create_user.sql
 │       └── 3_grant.sql
 └── sonarqube
 4 directories, 5 files

Mysql Configure

Create file ./mysql/conf/custom.cnf

The content as below

[mysqld]
character-set-server=utf8
lower_case_table_names=1
explicit_defaults_for_timestamp=true

Create two Database

Create the database with “./mysql/init/1_create_db.sql” file.

-- For WebApp
CREATE DATABASE IF NOT EXISTS items DEFAULT CHARACTER SET UTF8;
-- For SonarQube
CREATE DATABASE IF NOT EXISTS sonar DEFAULT CHARACTER SET UTF8;

User for SonarQube

Create a user with “./mysql/init/2_create_user.sql” file

CREATE USER 'sonar' IDENTIFIED BY 'sonar';

Grant user

Grant user for sonar with “./mysql/init/3_grant.sql” file.

GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
FLUSH PRIVILEGES;

Example docker-compose file as below

version: '3.5'
services:
 mysql:
     image: mysql:5.7.21
     container_name: mysql
     ports:
       - 3306:3306
     volumes:
       - ./mysql/init:/docker-entrypoint-initdb.d
       - ./mysql/conf/:/etc/mysql/conf.d
     networks:
       - sonarnet
     environment:
       MYSQL_ROOT_PASSWORD: root
     restart: always
 sonarqube:
     image: sonarqube:7.0
     container_name: sonarqube
     depends_on:
       - mysql
     volumes:
       - sonarqube_conf:/opt/sonarqube/conf
       - sonarqube_data:/opt/sonarqube/data
       - sonarqube_extensions:/opt/sonarqube/extensions
       - sonarqube_bundled-plugins:/opt/sonarqube/lib/bundled-plugins
     networks:
       - sonarnet
     command: -Dsonar.web.context=/sonarqube
     ports:
       - 9000:9000
       - 9092:9092
     environment:
       - SONAR_JDBC_USERNAME=sonar
       - SONAR_JDBC_PASSWORD=sonar
       - SONAR_JDBC_URL=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
     restart: always
networks:
   sonarnet:
     driver: bridge
volumes:
   sonarqube_conf:
   sonarqube_data:
   sonarqube_extensions:
   sonarqube_bundled-plugins:

Build and start with Docker-compose

$ cd docker
$ docker-compose -f docker-compose.yml up -d

Access to SonarQube login page

  • Link access: http://127.0.0.1:9000/sonarqube
  • User/Password: admin/admin

As a result the picture below

Stop SonarQube with Docker-compose

$ cd docker
$ docker-compose -f docker-compose.yml stop

You have Docker-compose Build SonarQube. Thank you for reading! Thank you for reading the DevopsRoles page!