Docker - eamonstackpole/my-tech-journal GitHub Wiki

Overview

  • In this lab we learned how to use docker to create containers, specifically a container for wordpress and mariadb.

Configuring Ubuntu

IP & Hostname

Hostname

  • There are two options for changing the hostname:
    • hostnamectl set-hostname new-hostname
    • sudo vi the /etc/hostname and /etc/hosts files

/etc/hostname

image

/etc/hosts

image

  • sudo systemctl reboot

IP Address & Netplan

  • sudo vi /etc/netplan/00-installer-config.yaml
  • configure it similarly:

image

  • NOTE(3/2/24): Gateway4 is deprecated, use the following formatting instead:

image

  • sudo netplan apply

Securing SSH

  • Same as CentOS, check here

Installing Docker

image

  • sudo apt install docker-ce
  • Check that it is running using sudo systemctl status docker

Giving an account Docker privileges

  • sudo usermod -aG docker (accountname)

  • use the group command to double check you are part of the group

  • use the version command to see all the information about the version of Docker you are using:

image

Running Docker Commands

  • use the run command to create containers of images and execute them (if the image is not found it will be downloaded) image

    • the -d option makes it run in the background
    • the -P option makes Docker bind the exposed ports to random ports on the host

Installing Docker-Compose

image

  • The Docker ps command shows the currently running containers

image

WordPress

  • Create the Docker-Compose file using vi docker-compose.yml

Configure Docker-Compose File

  • Configure the file similar to below: image

Running, Creating, & Closing the Containers

  • To create the containers use the command docker-compose up -d

  • Go to http://IPaddress:8000 to configure and customize the Wordpress

image

  • To close the containers use the command docker-compose down

Sources