Exploring Docker
Lección 3 de 3 · Quick WordPress Setup With Docker · Programación
Quick WordPress Setup With Docker
[Music] this video is sponsored by dev Mountain if you're interested in learning web development iOS or UX design dev
Mountain is a 12-week design and development boot camp intended to get you a full-time position in the industry to learn more visit dev mountain comm or click the link in the description below
hey what's going on guys so in this video I'm going to show you how to set up an entire WordPress environment within docker and I'm not gonna go over the basics of docker I have a two series
or two video series called getting started with docker where we talk about containers and images and all that stuff the different commands what we're gonna do is create a docker compose file with
a few different services that we can just create on the fly and the reason for that I'm doing this is because I want to do a tutorial on headless WordPress where we basically use the
WordPress API so we can use the content management system but also use react or view or something on the front-end by using the REST API that word press provides so I wanted a quick and easy
way to get WordPress set up so instead of installing something like xampp and going through all that rigmarole we're just going to use docker create a single file we're on a single command and it's
gonna set up everything and it's not even going to be on our machine it's going to be within docker containers alright so obviously you do need docker installed you can just go to docker calm
and install it and then I'm gonna show you the different images we're going to be using so this is hub docker comm and I'm just going to search for WordPress so basically we're using the official
WordPress image which includes Apache it includes PHP so all that stuff is taken care of but we do need MySQL as a container as well so if we search for MySQL and we take a look at this image
down here there's some environment variables that we're going to need so the root password the database we want to create a new user and password as well so this is stuff we're gonna have
to include in the docker compose file alright and then I also want to install PHP myadmin so for you search for that PHP myadmin which is
this one right here basically this will allow us to to view our tables and columns and stuff like that so I just want to create a single file that will set all of this stuff up for us all
right so let's jump into vs code and I'm just an empty folder called WordPress underscore site I already have docker installed and we're gonna create a new file here so I'm gonna say touch doc R –
compose dot yamo YAML and I'm just gonna open this up and I'm just gonna go through line by line and kind of explain what's going on so the first thing we want is the version of the compose file
which right now we want to do version 3 that's the the latest version and then we want our services and the indentation is really important so make sure you indent here our first service is going
to be our database so I'll actually put just put a comment here and say database and we're gonna call it DB so I want to do DB colon and then we want to indent over and then the image that we want to
use here is the MySQL image and we're gonna use five point seven all right so we have the image next thing we want is the volumes because we want to be able to save or persist to our database and
have it saved so four volumes we're gonna do actually going to go on to the next line and when we do this we need to put a tab and then a hyphen and then a space and we're gonna do DB underscore
data and map it to wherever MySQL is in the container which is going to be slash var slash leb slash my SQL okay so the next thing we're going to add is a restart policy of always so that if the
server reboots the container restarts and then our environment this is going to be our environment variables and if we go to the documentation for the MySQL image here and go down to environment
variables we need the root password the database and then I want to create a new user and pass for the WordPress installation because I don't want to use the route so let's do
MySQL underscore root underscore password and I'm just gonna set that to password and then let's do MySQL underscore database which I'll set to WordPress
okay we'll copy that down a couple times and then we want the MySQL user and the password for that user which will both be WordPress alright and then we want to set our networks because basically I
want all of our services to run on a docker Network and we're going to call that WP site okay and that could be you could call it whatever you want so next service we need is WordPress so
we'll set the image actually before we do that let's say depends underscore on it's going to depend on the DB service okay and the image is gonna be the WordPress image and we want the latest
version so colon latest alright and then we're also going to need to map ports because we need to access WordPress from our local machine so let's say ports and we want to put some quotes here we're
gonna say we want 8000 on our local machine to map to 80 within the container now notice we didn't put ports for our database service and the reason for that is we're connecting directly to
that container we're not we don't there's no need to expose it to our machine our local machine that we're on let me just put a comment here for this service so this is WordPress
okay now under ports let's let's also do restart always you start always and then we need volumes so WordPress obviously has files so we need to basically take the files that are in the container like
the WordPress admin folder the theme all that stuff and we want that to show up in here in our root folder so we need to map that we're gonna open some brackets and
quotes we're gonna say dot slash meaning this current folder that were in we want a map to slash var slash slash HTML because remember this word press image it has Apache it uses Apache and this is
the web root for Apache and that's where those WordPress files are stored so we want to basically pull those out into here or sync them up with this folder alright so we also need environment
variables for WordPress which is going to be WordPress underscore DB underscore host now the host is going to be this DB service so we're going to connect directly to this so DB on port 3306
which is the default port for mysql alright let's let's bring this down a couple times so we need a DB user as well which is going to be WordPress and we're gonna change this to WordPress as
well and this is going to be DB password so these two should match these two because this is the user and password we're using okay and then we just want to define networks for this as well
so networks and we're gonna say WP site all right now I'm gonna do PHP myadmin after but before we can do this we need to map the volume of DB data and the network of WP sites so we're gonna go on
the first line here and our first column whatever and we're gonna say networks : and WP sites : okay we also want to do volumes : and then DB underscore data : alright so save that and that should be
enough for us to set up to set up our container so if we go down here and I do a docker PS what this does is shows us the containers on my machine which you can see I've cleared out
now if I do a docker images I do have the three images on my machine so you're if you're following along yours will take a little longer because it will have to pull or download them from
docker hub so mine will go a little faster but either way we're gonna do docker – compose up – D for detached and what it's going to do is first create the network and it's going to be
prefixed with whatever my folder name is in my case WordPress site and then create the volume create the database all that stuff and you can see the files are starting to show up over here
alright now you want to wait until these files all come in before you visit port 8000 but I just want to show you now if I do docker PS you can see we have our two container IDs and the images
WordPress lattice and MySQL and you can see WordPress's map to port 8000 so now I'm going to open a browser and I'm gonna go to HTTP localhost port 8000 and it should take us to an installation
page so we can go through and we can now install WordPress say my website admin and install WordPress login and that's it so I mean you know we went through and we created the docker
compose file but I'm gonna have that file in the description so you can simply take that file and just run docker compose up dash D and it will set up all this stuff for you all right
we're all we're also gonna add PHP myadmin but just to show you we can visit the front end here of WordPress this is the new 2019 theme which is very plain if we wanted to change it we could
go to appearance themes and activate the old theme here and reload there it is if we want to change something like let's go to posts we'll change the title here I'll just say hi there
update and reload and you can see that it is persisting to MySQL alright so let's go back to the docker compose and I'm going to go between the database in WordPress and create the oops create the
PHP myadmin service so we're gonna call it PHP myadmin and this also depends on the database so let's say depends on – DB and the image we're using is PHP my admin slash PHP myadmin that's what it's
called on docker hub so that's what we're going to use here alright let's also set the restart to always and we need to open a port ports because we need access to this
from our local machine right so I'm gonna say 8080 on our local machine we want to map to 80 in the container okay and then let's do our environment so our environment we have two things we have
the PMA which i think is PHP myadmin underscore what is it underscore hold on a second so we're just gonna head to PHP myadmin tickets database or root password so all
port we need the port p.m. a port and then we also need the MySQL root password which is right here so we need those two things so p.m. a port and we're gonna set for that not poor we
don't need port we need host sorry host is gonna be DB and then MySQL underscore root underscore password is password just like we set up here okay so I think that should be good let's also add our
network so networks WP site alright good let's save that and now I'm gonna go down here and I'm gonna once again run docker compose up dash D and let's go back and just just to show you and this
should still be fine if we reload our WordPress site you can see everything's good the changes are still there however now I can go to HTTP localhost port 8080 brings up PHP myadmin we have our root
user and the password should be password and there we go and you can see over here we have our WordPress database with all of our tables and everything like that so good
and if we look at privileges you can see that we have our WordPress user here so I mean that's pretty much it guys it's it's all setup I'm gonna put this this file here in the description probably in
a github gist so if you have docker installed simply run docker compose up dash D and it will set all this stuff up for you and you'll be ready to go alright so like I said I will be doing a
tutorial on headless WordPress soon but I mean you could use this just to create a regular WordPress site as well alright so hopefully you guys like this if you did please leave a like and I'll see you
in the next video
Setup WordPress, MySQL & PHPMyadmin in literally seconds with a single command using the Docker compose file we create in this video
Sponsor: DevMountain Bootcamp
https://goo.gl/6q0dEa
Github Gist With File:
https://gist.github.com/bradtraversy/faa8de544c62eef3f31de406982f1d42
Exploring Docker – Part 1:
💖 Become a Patron: Show support & get perks!
http://www.patreon.com/traversymedia
Website & Udemy Courses
http://www.traversymedia.com
Follow Traversy Media:
https://www.facebook.com/traversymedia
Posts by traversymedia
https://www.instagram.com/traversymedia