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
/etc/hosts
- sudo systemctl reboot
IP Address & Netplan
- sudo vi /etc/netplan/00-installer-config.yaml
- configure it similarly:
- NOTE(3/2/24): Gateway4 is deprecated, use the following formatting instead:
- sudo netplan apply
Securing SSH
- Same as CentOS, check here
Installing Docker
- sudo apt update
- sudo apt install apt-transport-https ca-certificates curl software-properties-common
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
- Check to make sure you are downloading using the docker repo and not ubuntu
- apt-cache policy docker-ce
- Output should look like this
- 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:
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)
-
- 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
- sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
- sudo chmod +x /usr/local/bin/docker-compose
- to verify the install and check the version use docker-compose --version
- The Docker ps command shows the currently running containers
WordPress
- Create the Docker-Compose file using vi docker-compose.yml
Configure Docker-Compose File
- Configure the file similar to below:
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
- To close the containers use the command docker-compose down