Lab 02: Docker - squatchulator/Tech-Journal GitHub Wiki

Lab 02: Docker

docker01 Setup

  • There should be a new VM for you called docker01 on the SYS265 section of vCenter. Put it on the LAN adapter and boot.
  • Login using the default creds and create a new user, elevate it to a sudo account, and rename the box to docker01-firstname.
  • Since it's Ubuntu server, we are gonna need to use netplan to get it connected. Remember, to do this you edit the file /etc/netplan/00-installer-config.yaml and add the following:

image

  • Now edit /etc/cloud/cloud.cfg and set preserve_hostname to true.
  • Also edit /etc/hosts and change the loopback hostname.
  • Open mgmt01 and add DNS records for this new box we just made (A and PTR)
  • Edit the file /etc/resolv.conf and add firstname.local after the search field, replacing the period there. Save and reboot the server.

Docker Setup

  • Run the following commands as root to install Docker from the Docker Repository:
apt update
apt install -ycurl  apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
apt-cache policy docker-ce
apt install docker-ce
usermod -aG docker ${USER}
su - ${USER}
  • Check that it's running and working properly with systemctl. Also ensure that it is accessable via your sudo user by running docker version.

Docker-Compose Setup

  • Run the following commands as root to install Docker-Compose from the Docker Github page:
curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version
  • To test, you can run something similar to this to output a test message:
docker run --rm archlinux:latest /bin/echo "Test Message"
  • You can also view existing downloaded images with docker images. If you want to see information about the currently running container, run docker ps. You can stop with docker stop <container>

Containerized Wordpress

  • In your home directory, make two new files: compose.yaml and README.md.
  • Add the following to compose.yaml:
services:
  db:
    # We use a mariadb image which supports both amd64 & arm64 architecture
    image: mariadb:10.6.4-focal
    # If you really want to use MySQL, uncomment the following line
    #image: mysql:8.0.27
    command: '--default-authentication-plugin=mysql_native_password'
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=somewordpress
      - MYSQL_DATABASE=wordpress
      - MYSQL_USER=wordpress
      - MYSQL_PASSWORD=wordpress
    expose:
      - 3306
      - 33060
  wordpress:
    image: wordpress:latest
    ports:
      - 80:80
    restart: always
    environment:
      - WORDPRESS_DB_HOST=db
      - WORDPRESS_DB_USER=wordpress
      - WORDPRESS_DB_PASSWORD=wordpress
      - WORDPRESS_DB_NAME=wordpress
volumes:
  db_data:
  • Deploy with docker compose up -d and navigate to http://docker01-miles to see your Wordpress site!
⚠️ **GitHub.com Fallback** ⚠️