📺 Develpreneur YouTube Episode

Video + transcript

WordPress on Docker - Part 2

2022-02-03 •Youtube

Detailed Notes

This series is a short set of tutorials on setting up a docker instance to run and develop your Wordpress installation.

Transcript Text
[Music]
there we go all right so we want to
start
with a doctor compose
yml file so yet another modeling
language file
so if we look at this file
boom
and the reason i'm doing all this from
command line where i could do this in
notepad is typically in production or
when you're dealing with live
environments you don't have a gui so
you're going to have to either ssh in
ftp into or
ssh into your site so that you can
actually work behind the scenes in the
operating system
so we'll use bim or buy
and go into our file and see what we
have
so you want to start out by giving it
the version of the compose that you want
to use in this case 3.7
we're going to start out we're going to
set up our
services
the first one here is going to uh
just fit the comments so this is for our
database
uh we're going to set up our database
with a platform of linux x86 underscore
64.
if you are on the mac m1 chip
you must specify this if you're on any
other environment this is not
necessarily required if you just specify
linux it will just build a linux
environment but for the m1 chip this is
the linux emulator that docker currently
supports
so
if you want to load linux make sure you
have this one
then we tell it what version of mysql we
want to install in this case 5.7
we're going to tell it where to build
our database volume it's going to be in
var live my sql
restart always so if we actually make
any changes to the mysql configuration
it will automatically cause a restart
we're also going to set our environment
variables here so we're going to set the
root password as password and we're
going to set up a default uh database
user and password for wordpress and then
for this example it's all wordpress
not what you want to do in production
but this is just a local development
site so this is what we need
and then networks we're just going to
dedicate it to a wp site
so that's our first container so this is
our database
now if you don't specify platform again
it will use this one by default for the
rest of your containers in the same
yaml file
so we come down here so next
it's not mandatory but i highly
recommend that you install the
phpmyadmin
as another container uh this will depend
on the database settings it's going to
use the image php my admin
again it's we're going to set it to
restart always if we make any changes to
the backend
and here is where we actually specified
the port so where up here we did not
specify the port for my sql so it's
going to use the default
but here we are going to specify the
port
because these ports are the ports that
are going to be open to our browser so
this is how we can actually access our
website through the browser
so we're going to set up our pma host to
be our database so it's going to go up
to the database and we're going to use
the mysql root password password so
we're going to set php admin to
coincide work hand in hand with my sql
now these are going to be running in
different containers those but this is
really cool so you can set this up and
wire them together here
again you set to the same network wp
site
and then finally we're going to set up
wordpress
so wordpress again is going to depend on
the mysql database
notice this is not pointing to php admin
wordpress does not care about php admin
php admin is just a
web-based
database interface that you can use to
work with your any database
wordpress needs
to point to a mysql database so here we
give it our database reference
we're going to install the latest
wordpress
image
and we're going to specify its web ports
to be 12 0002
again restart always and we're going to
set its default volume to root bar
www.html
and then we do need to specify the
wordpress host user and password for
default so when it starts up it knows
how to log in and connect to the
database
network wordpress site
network wordpress volumes tv data
okay any questions on the yaml file
everyone clear
okay so there's our yama
takes it out
so to bring up our doctor we need to use
the doctor compose command
again
but in this case we're going to use the
up command to bring up our container
and use the d for the current directory
this will start
see this will start the download and the
uh
start downloading the images and run the
containers for them
this will take just a minute to run
and this pulls down those containers and
the images in the order that they were
defined in the
compose file so we start out by setting
up the mysql then the php admin and then
finally it will do the wordpress
download and fill
as you can see this is pretty quick
we're already on the
wordpress almost done
so much easier than having to set up a
vm and then actually downloading the
software or setting up the software
uh
multiple times or even if you were to
create a vm
master image file you still have to
maintain the updates to
wordpress to
my sequel to php admin this is a very
simple way to constantly build or update
your environments without having to
constantly go in and build a whole
operating system and manage and
configure
all right so
let's look at what we have so if we look
at our directory here are all of our
config files for wordpress so we have
our wordpress config we have our
wordpress content
we even have
this
so if we actually look we also have our
dot ht access which is hidden
uh we have our index.php
wordpress active
so we have all of our wordpress sites
including the htaccess file which this
will be necessary once we export our
files
uh or i should say import our exported
live wordpress site because we're going
to have to make a few changes locally so
that the wordpress site
worked uh because there are some
customizations in other environments
that don't always work when you move
them to different systems
all right the other thing we want to
make sure is all right so we know that
we have our container
and so let's start and see what images
we were built we want to use docker
and the images command
and this is going to tell us that hey
look it's built as a wordpress image on
my sql image and a php admin image
and if i
and also because we did the docker up
the container should actually be live so
if we use the docker
pf command
we can see that we do have three images
running we have php admin wordpress and
mysql they've all been up for two
minutes
it also tells you the redirect for each
of these so if you forget you can always
run the doctor ps command to see which
reports you need for php admin
403 because 430
and wordpress 12.0 12002
80 and my sequel 4306
now 3306 is the default mysql port and
since we didn't specify that in the yaml
file it automatically is defaulted to
the default
so that is from the command line now if
we're on our local machines
if we go to our docker desktop we now
see we have a wordpress container
running and if we expand out the
container we see that we have a
wordpress database we have a wordpress
php admin and we have a wordpress
wordpress site running the wordpress is
our the overall container with the three
different components we have the
database the php admin and wordpress
if we want to go actually look at the
logs for each of these we can click on
them and it will give you the command
line
logs so you can kind of look through and
see if something's going on
you can actually jump out to the command
line for each of these
so now i'm actually on the wordpress box
i can
so that's from the wordpress container
if i want to go to the individual boxes
so i can go to wordpress db
there's a wordpress database logs
i want to go to php admin because php
admin also has a redirect to the web i
can also go and click here and just jump
right out to the web browser
a very quick navigation
uh within docker so you don't have to
constantly remember oh where did i
configure this you can just manage
everything from within the docker
desktop and then wordpress we can also
click the link here and take us to our
wordpress site
up fairly and there it is
so the other thing to notice in our
doctor desktop is we have this image tab
over here now this is going to show you
that we have three containers that have
been downloaded and installed locally we
have wordpress mysql and php admin
now it's saying that these are in use
because these containers are currently
running underneath this master container
wordpress
and they all contain the volume
for the wordpress database so here is
our database here so any configuration
changes we make to the container
will be stored
in this volume
now we can create additional volumes and
point to them as well uh one thing to be
careful of if you do screw up and you
want to start over you must delete this
file because these containers currently
point to this volume
if you do not
if you just leave these images and don't
delete the container or the volume when
you go to start again it's going to
start up and you're going to have all
the same settings from your previous
install so it's going to still be broken
so if you need to start over you need to
delete everything
you do not need to delete the images
though because
this will save you time
so the next time you actually run the
docker compose up
instead of downloading the containers if
these are the latest containers it will
reuse these when it builds your
container application
i know that was a lot is everyone clear
on
the docker desktop
yes sir yes sir
okay cool
all right so now let's go set up our
wordpress so even though we are trying
to restore a backup from a live system
it is so much easier to do it from
within wordpress using the plugins so
we'll just quickly jump in and do a very
simple wordpress install we'll just call
it demo
username demo
password demo
confirm firmly password
and we'll just throw in my
email address here
and just third
search engines from indexing your site
when you are pushing this locally uh you
want to do this because you don't really
want web browsers to try and find your
site on your local machine
it's all wordpress this really doesn't
take any time at all
unfortunately though once you do this
you do have to go back in and tweak a
file
we now have our wordpress site
demo there you go
so if this is all you're doing if you're
just getting started with wordpress this
is where
my presentation would end however we
want to actually export our production
and site melash consulting and actually
import it into
uh this local container so the first
thing i want to do um before i do
anything is come back over here to my
php my admin
and make sure that i can log in this
site
press
and again
so i'm in
my php my admin so i can now connect to
my wordpress database
we'll we will need this in case we need
to update live urls
all right so the first thing we want to
do is go to plugins now on wordpress
and we want to search for
the all-in-one
you
Transcript Segments
1.35

[Music]

26.32

there we go all right so we want to

28

start

29.039

with a doctor compose

31.84

yml file so yet another modeling

34.239

language file

35.68

so if we look at this file

38.32

boom

39.28

and the reason i'm doing all this from

40.96

command line where i could do this in

42.399

notepad is typically in production or

45.6

when you're dealing with live

47.2

environments you don't have a gui so

49.92

you're going to have to either ssh in

52.32

ftp into or

54.64

ssh into your site so that you can

56.399

actually work behind the scenes in the

58.559

operating system

61.44

so we'll use bim or buy

63.52

and go into our file and see what we

65.84

have

66.56

so you want to start out by giving it

68.32

the version of the compose that you want

70.32

to use in this case 3.7

73.04

we're going to start out we're going to

74.32

set up our

75.6

services

76.96

the first one here is going to uh

80

just fit the comments so this is for our

81.759

database

82.96

uh we're going to set up our database

84.479

with a platform of linux x86 underscore

88.32

64.

90.079

if you are on the mac m1 chip

93.04

you must specify this if you're on any

96.159

other environment this is not

97.84

necessarily required if you just specify

101.439

linux it will just build a linux

104.079

environment but for the m1 chip this is

107.28

the linux emulator that docker currently

109.92

supports

110.88

so

111.68

if you want to load linux make sure you

113.68

have this one

115.84

then we tell it what version of mysql we

117.6

want to install in this case 5.7

120.32

we're going to tell it where to build

122.719

our database volume it's going to be in

124.719

var live my sql

127.2

restart always so if we actually make

128.959

any changes to the mysql configuration

131.68

it will automatically cause a restart

134.48

we're also going to set our environment

136.08

variables here so we're going to set the

138.08

root password as password and we're

140.56

going to set up a default uh database

143.2

user and password for wordpress and then

145.52

for this example it's all wordpress

148.16

not what you want to do in production

149.599

but this is just a local development

151.28

site so this is what we need

153.28

and then networks we're just going to

155.84

dedicate it to a wp site

159.76

so that's our first container so this is

161.76

our database

163.2

now if you don't specify platform again

166.16

it will use this one by default for the

168.48

rest of your containers in the same

170.959

yaml file

172.48

so we come down here so next

175.84

it's not mandatory but i highly

178.08

recommend that you install the

179.599

phpmyadmin

181.44

as another container uh this will depend

184.879

on the database settings it's going to

187.519

use the image php my admin

190.48

again it's we're going to set it to

192.319

restart always if we make any changes to

194.72

the backend

196.159

and here is where we actually specified

198.64

the port so where up here we did not

201.12

specify the port for my sql so it's

203.2

going to use the default

204.879

but here we are going to specify the

207.12

port

208

because these ports are the ports that

209.68

are going to be open to our browser so

211.84

this is how we can actually access our

213.44

website through the browser

218.879

so we're going to set up our pma host to

221.28

be our database so it's going to go up

223.12

to the database and we're going to use

225.36

the mysql root password password so

227.36

we're going to set php admin to

230.64

coincide work hand in hand with my sql

234.319

now these are going to be running in

235.84

different containers those but this is

237.84

really cool so you can set this up and

240.319

wire them together here

242.64

again you set to the same network wp

245.12

site

247.76

and then finally we're going to set up

249.92

wordpress

252.08

so wordpress again is going to depend on

254.239

the mysql database

256.639

notice this is not pointing to php admin

260.239

wordpress does not care about php admin

263.12

php admin is just a

265.6

web-based

266.88

database interface that you can use to

269.28

work with your any database

272.96

wordpress needs

274.56

to point to a mysql database so here we

277.199

give it our database reference

279.44

we're going to install the latest

281.44

wordpress

283.12

image

284.32

and we're going to specify its web ports

286.32

to be 12 0002

290.479

again restart always and we're going to

293.12

set its default volume to root bar

296.479

www.html

298.96

and then we do need to specify the

300.88

wordpress host user and password for

303.199

default so when it starts up it knows

305.6

how to log in and connect to the

307.52

database

308.72

network wordpress site

310.8

network wordpress volumes tv data

315.199

okay any questions on the yaml file

321.199

everyone clear

330.639

okay so there's our yama

335.44

takes it out

337.68

so to bring up our doctor we need to use

340.8

the doctor compose command

343.68

again

344.639

but in this case we're going to use the

346.4

up command to bring up our container

349.28

and use the d for the current directory

354.96

this will start

357.919

see this will start the download and the

360.639

uh

361.44

start downloading the images and run the

363.36

containers for them

366

this will take just a minute to run

377.759

and this pulls down those containers and

380.08

the images in the order that they were

382.24

defined in the

384.319

compose file so we start out by setting

386.639

up the mysql then the php admin and then

390

finally it will do the wordpress

391.919

download and fill

402.319

as you can see this is pretty quick

404.72

we're already on the

406.84

wordpress almost done

422.319

so much easier than having to set up a

424.319

vm and then actually downloading the

426.4

software or setting up the software

429.12

uh

429.84

multiple times or even if you were to

432.08

create a vm

433.52

master image file you still have to

435.599

maintain the updates to

438.08

wordpress to

440.8

my sequel to php admin this is a very

443.919

simple way to constantly build or update

446.96

your environments without having to

449.759

constantly go in and build a whole

451.52

operating system and manage and

453.039

configure

455.759

all right so

457.919

let's look at what we have so if we look

460.16

at our directory here are all of our

463.199

config files for wordpress so we have

465.919

our wordpress config we have our

468.16

wordpress content

472.4

we even have

474.879

this

483.599

so if we actually look we also have our

486.4

dot ht access which is hidden

488.96

uh we have our index.php

491.36

wordpress active

495.36

so we have all of our wordpress sites

497.28

including the htaccess file which this

500.319

will be necessary once we export our

502.639

files

503.68

uh or i should say import our exported

506.8

live wordpress site because we're going

508.8

to have to make a few changes locally so

511.12

that the wordpress site

512.8

worked uh because there are some

514.64

customizations in other environments

516.719

that don't always work when you move

518.24

them to different systems

526.56

all right the other thing we want to

527.92

make sure is all right so we know that

530.72

we have our container

532.64

and so let's start and see what images

535.44

we were built we want to use docker

539.36

and the images command

542.72

and this is going to tell us that hey

544.24

look it's built as a wordpress image on

546.399

my sql image and a php admin image

552.64

and if i

554.48

and also because we did the docker up

557.36

the container should actually be live so

560.08

if we use the docker

562.72

pf command

565.12

we can see that we do have three images

567.519

running we have php admin wordpress and

570

mysql they've all been up for two

571.68

minutes

572.72

it also tells you the redirect for each

575.839

of these so if you forget you can always

578.24

run the doctor ps command to see which

581.839

reports you need for php admin

584.959

403 because 430

587.68

and wordpress 12.0 12002

591.12

80 and my sequel 4306

595.279

now 3306 is the default mysql port and

598.24

since we didn't specify that in the yaml

600.64

file it automatically is defaulted to

603.6

the default

609.2

so that is from the command line now if

611.92

we're on our local machines

614.48

if we go to our docker desktop we now

617.04

see we have a wordpress container

619.519

running and if we expand out the

621.519

container we see that we have a

623.6

wordpress database we have a wordpress

626.72

php admin and we have a wordpress

630.399

wordpress site running the wordpress is

632.32

our the overall container with the three

634.56

different components we have the

635.92

database the php admin and wordpress

639.04

if we want to go actually look at the

640.72

logs for each of these we can click on

642.32

them and it will give you the command

643.92

line

645.519

logs so you can kind of look through and

647.519

see if something's going on

650.399

you can actually jump out to the command

652.24

line for each of these

657.12

so now i'm actually on the wordpress box

665.92

i can

668.48

so that's from the wordpress container

670.32

if i want to go to the individual boxes

672.88

so i can go to wordpress db

675.44

there's a wordpress database logs

678

i want to go to php admin because php

680.959

admin also has a redirect to the web i

683.68

can also go and click here and just jump

686.72

right out to the web browser

688.48

a very quick navigation

690.72

uh within docker so you don't have to

692.959

constantly remember oh where did i

694.32

configure this you can just manage

696.24

everything from within the docker

698.72

desktop and then wordpress we can also

700.959

click the link here and take us to our

702.88

wordpress site

707.2

up fairly and there it is

711.12

so the other thing to notice in our

713.12

doctor desktop is we have this image tab

715.839

over here now this is going to show you

717.839

that we have three containers that have

719.68

been downloaded and installed locally we

722.24

have wordpress mysql and php admin

725.6

now it's saying that these are in use

727.6

because these containers are currently

729.68

running underneath this master container

731.68

wordpress

733.68

and they all contain the volume

736.24

for the wordpress database so here is

738.639

our database here so any configuration

741.36

changes we make to the container

743.68

will be stored

745.279

in this volume

746.88

now we can create additional volumes and

749.36

point to them as well uh one thing to be

751.839

careful of if you do screw up and you

754.399

want to start over you must delete this

756.88

file because these containers currently

759.839

point to this volume

761.68

if you do not

763.519

if you just leave these images and don't

765.92

delete the container or the volume when

768.48

you go to start again it's going to

771.44

start up and you're going to have all

773.519

the same settings from your previous

775.6

install so it's going to still be broken

779.04

so if you need to start over you need to

781.12

delete everything

783.12

you do not need to delete the images

784.959

though because

786.399

this will save you time

788.399

so the next time you actually run the

789.839

docker compose up

791.6

instead of downloading the containers if

794.399

these are the latest containers it will

796.72

reuse these when it builds your

798.72

container application

802.72

i know that was a lot is everyone clear

804.88

on

805.76

the docker desktop

815.12

yes sir yes sir

816.88

okay cool

818.24

all right so now let's go set up our

820.72

wordpress so even though we are trying

823.279

to restore a backup from a live system

826.88

it is so much easier to do it from

828.72

within wordpress using the plugins so

831.44

we'll just quickly jump in and do a very

834.079

simple wordpress install we'll just call

835.92

it demo

837.279

username demo

838.88

password demo

840.72

confirm firmly password

842.8

and we'll just throw in my

847.6

email address here

850

and just third

851.44

search engines from indexing your site

854.56

when you are pushing this locally uh you

857.6

want to do this because you don't really

859.199

want web browsers to try and find your

861.519

site on your local machine

864.48

it's all wordpress this really doesn't

866.639

take any time at all

870.32

unfortunately though once you do this

872.88

you do have to go back in and tweak a

875.839

file

894.8

we now have our wordpress site

898

demo there you go

900

so if this is all you're doing if you're

901.519

just getting started with wordpress this

903.6

is where

904.56

my presentation would end however we

907.279

want to actually export our production

910.24

and site melash consulting and actually

912.56

import it into

914.32

uh this local container so the first

917.12

thing i want to do um before i do

919.199

anything is come back over here to my

920.959

php my admin

923.12

and make sure that i can log in this

925.36

site

930.8

press

934.88

and again

936.16

so i'm in

937.519

my php my admin so i can now connect to

940.399

my wordpress database

944.32

we'll we will need this in case we need

946.399

to update live urls

950

all right so the first thing we want to

951.519

do is go to plugins now on wordpress

960

and we want to search for

963.04

the all-in-one

981.519

you