Docker

Installing docker on ubuntu 20


            $  sudo apt update
            $  sudo apt install docker.io
        
* This method installs from official ubuntu repositories

Verify the installed version


            $  docker --version
        

Enable docker on system reboot


            $  sudo systemctl enable --now docker
        

Login to docker registry


            $  sudo docker login
        

Verify docker run


            $ docker run hello-world
        

Basic docker commands

List docker information


            $  docker info
        

List docker images


            $  docker images
        

List docker containers


            $  docker ps
        

Kill a container


            $  docker kill <container-name>
        

Start a non-running container


            $  docker start <container-name>
        

Stop a container


            $  docker stop <container-name>
        

Docker volumes

Docker volumes are used by docker containers for persisting data. Volumes are completely managed by docker itself and are easier to backup, share and it works on any platform.

Create a docker volume


            $  docker volume create <volume name>
        

List available docker volumes


            $  docker volume ls
        

Inspect a docker volume


            $  docker volume inspect <volume name>
        

Running Jenkins on docker

Pull the official jenkins LTS docker image


            $  docker pull jenkins/jenkins:lts
        

for a lighter image size use alpine-based image


            $  docker pull jenkins/jenkins:lts-alpine
        

Run the jenkins image with a mounted volume and as a name container for configuration persistence


            $  docker run -d -p 8080:8080 -v jenkins-dev:/var/jenikins_home --name jenkins-dev jenkins/jenkins:lts-alpine
        
* here "jenkins-dev" is given name to both the newly created docker volume and the jenkins container

Verify if the container is running successfully at http://<hostname>:8080

During the first run Jenkins would require an administrator password, this can be found at /var/jenkins_home/secrets/initialAdminPassword and can be fetched through this command -


            $  docker exec <container-name> cat /var/jenkins_home/secrets/initialAdminPassword
        

Apache2 web server on Ubuntu

Installing apache2 on Ubuntu


        $ sudo apt update 
        $ sudo apt install apache2
        

Apache comes with a default site. The contents are located at /var/www/html and its settings are in a Virtual Host file at /etc/apache2/sites-enabled/000-default.conf

Create directory for the new site


        $ mkdir /var/mysite
        

Creating the virtual host for the new site

Clone the configuration file of default site for the new site


        $ cd /etc/apache2/sites-available/
        $ cp 000-default.conf mysite.conf        
      

Edit the new configuration file to update the new port number(optional), ServerAdmin, DocumentRoot & add Permissions


        $ sudo nano /etc/apache2/sites-available/mysite.conf
        

The configuration file should look something like this -


        <VirtualHost *:8081>
          ServerAdmin dev@localhost
          DocumentRoot /var/mysite
  
          <Directory /var/mysite>
              Options Indexes FollowSymLinks
              AllowOverride All
              Require all granted
          </Directory>
  
          ErrorLog ${APACHE_LOG_DIR}/error.log
          CustomLog ${APACHE_LOG_DIR}/access.log combined
  
          #Include conf-available/serve-cgi-bin.conf
        </VirtualHost>
      

Configure apache to listen to the new port


        $ sudo nano /etc/apache2/ports.conf
        

Add the following lines for the new port


        NameVirtualHost *:8081
        Listen 8081
        

Activate the virtual host


        $ sudo a2ensite mysite.conf
        

Reload the apache service to load new configuration


        $ sudo systemctl reload apache2
        or
        $ sudo service apache2 reload
        

Test the new site at http://<hostname>:8081/