Lab 3: Docker - adaley0518/Tech_Journal GitHub Wiki

Lab 3: Docker. This lab was done with Ubuntu 18.04 cloud server. The following information will be about learning how to configure and use Ubuntu. Also, we will be learning different commands and ways to use docker.

Network Configuration with Netplan

  • First, figure out the name of the network interface to configure
    • ip a (in my case ens160)
  • Next, find the file that you will need to use to configure, it can vary
    • ls /etc/netplan/ (the file I had is 50-cloud-init.yaml)
  • Now open the configuration file and update the configuration
    • sudo vi /etc/netplan/50-cloud-init.yaml
    • the configurations follow:
network:
    Version: 2
    ethernets:
        ens160:
            dhcp4: false
            addressess:
                - 10.0.5.12/24
            gateway4: 10.0.5.2
            nameservers:
                addressess: [10.0.5.5]
                search: [amber.local]
  • save file and exit
  • test configuration, accept changes
    • sudo netplan try
  • apply configuration
    • sudo netplan apply
  • Restart network service
    • sudo systemctl restart systemd-networkd
  • Verify IP address
    • ip a

Change Host Name

  • Change hostname using hostnamectl
    • sudo hostnamectl set-hostname docker01-amber
  • Edit the /etc/hosts file
    • sudo vi /etc/hosts
    • change hostname to new one (keep localhost)
  • edit the cloud.cfg file
    • check if the package is installed
      • ls -l /etc/cloud/cloud.cfg
    • if installed will need to change info in the file
      • sudo vi /etc/cloud/cloud.cfg
      • search for 'preserve_hostname' and change value to 'true'
  • Verify the hostname has changed
    • hostnamectl
      • static hostname: docker01-amber (the host name of your choosing)

Named Sudo User

  • adduser amber
  • set the password and put in user info
  • usermod -aG sudo amber
  • Test sudo access
    • su - username

After all configurations, a reminder to add the system to DNS with A and PTR records.

Installing Docker

  • Step 1: Installation
    • update existing list of packages
      • sudo apt update
    • install packages
      • sudo apt install apt-transport-https ca-certificates curl software-properties-common
    • add GPG key for official Dcoker repository
    • add the Docker repository to APT sources
    • update package databases
      • sudo apt update
    • install the Docker repo
      • apt-cache policy docker-ce
    • install Docker
      • sudo apt install docker-ce
    • check docker is running
      • sudo systemctl status docker (should be active)
  • Step 2: Docker without Sudo
    • add user to docker group
      • sudo usermod -aG docker ${user}
      • su - ${user} (or log out and back in)
    • confirm your a dcoker user
      • id -nG (output: {user} sudo docker)
  • Step 3: Docker commands (for reference)
    • to view all subcommands
      • docker ( list of available commons will show)
    • to view options available to a command
      • docker docker-subcommand --help
    • to view system-wide information for Docker
      • docker info
    • useful commands include
      • docker version
      • docker run hello-world
      • docker run --rm archlinux:latest /bin/echo "HELLO SYS265" (change input)
      • docker images

Install Docker-Compose

  • install
    • apt install docker-compose
  • check version
    • docker-compose version

Docker Arch Linux Container

  • print out current version of Ubuntu on docker01 (or whatever system being used)
    • cat /etc/lsb-release
  • print out the current version of docker01's linux kernel
    • echo "current kernel is:$(uname -a)"
  • print out the Kernel being used by Ubuntu container
    • docker run -it archlinux /bin/uname -a

Docker Web Application

  • docker run -d -P training/webapp python app.py
  • use docker ps to check the image

Docker Networking

  • allow port 32768/tcp on firewall
    • sudo ufw allow 32768/tcp
  • reload firewall
    • sudo ufw reload/reset

Access Docker Web Application

  • http://docker01-amber:32768/ (should see hello world) *stop testapp
    • docker ps (find the name should be weird like zealous_brahmagupta)
    • docker stop zealous_brahmagupta (name can vary)
    • docker ps (should be empty)

Docker Wordpress

  • Step 1: Defining the Web Server Configuration
    • create directory
      • mkdir wordpress && cd wordpress
    • make directory for the configuration file
      • mkdir nginx-conf
    • open file
  • Step 2: Defining Environment Variables
    • open a file 'vi .env'
    • file should contain:
      • MYSQL_ROOT_PASSWORD=your_root_password
      • MYSQL_USER=your_wordpress_database_password
      • MYSQL_PASSWORD=your_wordpress_database_password
    • add .env to .dockerignore file so it doesn't end up on your containers when you are using this directory as your build context
      • vi .dockerignore (add .env, docker0compose.yml, .dockerignore)
    • openn docker-compose.yml
      • vi docker-compose.yml( the link has the file info, do not copy the certbot as it is not needed for this assignment)
    • in docker-compose.yml add port 8000
  • Step 3: modifying webserver Configuration
    • add port 8000 to firewall
      • sudo ufw allow 8000 (add any ports needed and reload)
    • recreate webserver
      • docker-compose up -d --force-recreate
    • check services are up
      • docker-compose ps
  • Step 4: Completing Installation Through the Web Interface