Docker on Debian Linux – Getting a Canned Container for WordPress

The Setting for this article:


If there is no outside nonsense going on, this is the way that the whole open-source and Docker universe is supposed to work.  You grab a container that has your operating system in it from a repository and run it as needed.

That means you grab it from the cloud.  When you have it you can do with it what you want and then either save it or throw it away.

All that is great, but it does go against my own Project Management training.  You did not make it so how do you know it does not have any problems with it like viruses or worse.

So Warning:  Only run a container that you create or one that you know to be safe. 

I am assuming that the container I am working with is safe because it is listed as official.  To be honest, I can’t say I know enough about Docker and this particular container to say that assumption is true.

The benefits of running a container from a repository:

In the case of this particular one, it saves me a lot of time.

I do not have to create the container, I can just use it.

I can save it on my computer, or not – it is up to me.

I can modify it as I like.

Not a long list, I’m sure you can add other items to it.  It took me about 10 minutes to grab the container and save it to my hard drive.  It takes about 2 hours to install Debian, then another couple hours to install LAMP, and more time install WordPress… and configuration time.  Someone at Docker did it for me.  This is why containers got popular.  In a large organization, you will have a standard container that gets cloned dozens of times for the designed purpose.

Since we’re going to simply use it, here are the steps to get a “canned” container onto your computer for WordPress.

 

1) Get your environment ready

Start your Docker compatible computer and make sure Docker is up and running.  A simple command like docker images will tell you the list of images you have available and what they are called.

2) Search the repository for the image you were given

What you need is a list of containers.  These are “out there on the cloud” and available at Docker for you to grab.  They may also be on your own cloud server if you’re at a business.  Typically someone will tell you “what to use” to get your job done.

We need a WordPress image.  You want to search.  docker search wordpress  will give you a list of all images that have wordpress in the name field.  Remember that “case counts” in Linux – all things are Case Sensitive as a Standard.

The one I feel safest choosing is the first one.  “wordpress”.  It has an official tag, 1601 stars, and I honestly am simply guessing.  Like I said in my preamble, if you want bulletproof security – create one from scratch.

3) Download the image with the “docker pull” command

This is pleasantly easy.  The image itself is called “wordpress” and all you need to get the latest image is to enter on the command line “docker pull wordpress“.  Docker will go out to its repository and make it available to itself.

At this point, you have in your hot little computer’s hands a copy of Debian Linux with WordPress.  If all you want to do is poke around and destroy at the end, you can stop reading, you’re done.

4) Verify that you have the image available to Docker

You can easily do this with another docker image command:

Having the wordpress image show on the REPOSITORY list proves things worked.

5) Prove that the image runs in Docker

You have it. Now how do you run the beast? 

First, check that images list.  There is a field called “IMAGE ID” in the list.  That is what Docker knows the images are called.  The Name is just a friendly name that you can change if you have a mind to.
Second execute the container using that IMAGE ID.  You will also want to be able to do something inside, so run /bin/bash as well.  That will allow you to control the container.

For my copy of wordpress the number to run is f6ae044a5122.  The command to run is “docker run -i -t f6ae044a5122 /bin/bash”  Your IMAGE ID will vary based on your list.

Notice that the prompt changes from root@elk to root@f6ae044a5122.  This tells you your computer changed and you are now “inside” the container.  You can enter normal bash commands here.

I am purposely getting out of the container with an “exit” command.  When you exit the container, it stops.

Finally, I need to know what docker called that container when it downloaded it.  Its name in the “NAMES” field is the key.  For me it is 8bb814e82c48.  I will need this to re-start the container in the next step.

6) Starting your Docker container, getting the container up to date.

The last step was to get out of the container.  That puts you back onto “your” computer.  You’re “local” now.  That is important because you will want to go back into docker to make sure you can.  It is an extra step, but it allows you to be careful.  Following that you will want to update the container.

You first need to start the container.  That is done with the docker start command.  My container is called 8bb814e82c48, and that is used here.  I do this by starting it with “docker start 8bb814e82c48“.

It’s running but you have to attach  the container.  In this case, I was able to have it drop me into a /bin/bash shell, automatically.  I do this with a “docker attach 8bb814e82c48” command.

Now that I am in the container, I want to update the container to current Debian – get all the software inside the container up to date.  This is done in the traditional way with the following three commands:

  1. apt update
  2. apt upgrade
  3. apt dist-upgrade

Finally it is necessary to get out of the container by entering an “exit command at the command prompt.

All except the exit are in the next graphic.

7) Commit your docker container to your local hard drive and give it a friendly name

That’s all great.  You have gotten the container up to date.  You need to be able to shut down the computer and make the container available for you when you come back from what ever you are doing out in the real world.  Right?

This is done with a few steps.

First you need to commit the container and give it a name.  Then you can verify your actions with an image.

Your container is the one you have been working with.  In my case it is 8bb814e82c48.  You need to commit this to the hard drive within Docker on the local machine.  I enter the command “docker commit 8bb814e82c48 wordpress“.  This gives the container the NAME of “wordpress”.  Terribly generic.  If you are running a couple containers at once, you will want to give it something more specific and meaningful.

Verify that Docker knows that it exists in its own table by entering a “docker ps -a” command.

Finally you can do a “docker images” command to show the list of containers you have access to.

8) Running your local copy of the Docker Container

Now that you have returned to your computer, or have stopped Docker, you are going to want to go through the motions of restarting it again.

First, the “docker images” command will give you the information you need.  It will tell you docker is up and running, and give you a list of containers you will need to do your thing.  The container is 8bb814e82c48 for me, your number will vary.  This corresponds to the container we committed to disk earlier.

Second, you can run some commands to start the container, attach to it, and verify that it is responding.  To start the container, you enter a command of “docker run -i -t 8bb814e82c48 /bin/bash“.  Attach to the container This will also put you inside the container and allow you to enter bash commands.

Finally, you can exit out of the container and go back to your local machine.

This is all listed in the following graphic.

9) How to actually access this specific container from the Docker Repository

Here is where I end for now.

What you have achieved is to grab a container from Docker and get the thing up to date.  You were able to save it locally, hopefully.  Finally you proved that it is verifiable and repeatable by running it again.

That gives you a server that you don’t know how to use.
I’m in the same boat at this point.  There is a long list of things you can do with the container, if you know how to get into it.  This specific container is a Docker produced container.  They have documented the steps for you to get access to it.

I will be returning to this and producing a cheat sheet in time as I get more used to the whole process.  I’m used to Debian and LAMP and doing it all “live” on a “real” computer (bare metal for the VMWare crowd), but this is still a learning process for me.

So once I get more helpful information, I’ll be back.  After all I have been at blogging since 2007.

The link from docker is here:

https://hub.docker.com/_/wordpress/

Good luck!

Advertisements

Docker on Debian Linux – Why and The Install of it All

If you want just the instructions, Skip to the break.  This is here basically so that I can do this again later.

The setting:

For almost all of what I do, I run Linux.  Specifically Debian Linux.

It runs much faster, has most of the same programs you’re used to on a Mac or a Windows PC, and is about as stable as an operating system can be. It can run some Windows programs in Emulation (WINE) but that’s not the point. I’ve got what I need if I stay within Linux, natively.

Some Debian Linux computers have “uptime”, time since they were last restarted, in years – not days or weeks.

I update things when I want.  I make things how I want them.  I change things how I want.  If there is one thing about Linux that Mac and Windows users don’t get to do is customize things the way that they want.

The backstory:

My blog resides in two places.  On www.ramblingmoose.com and on a WordPress hosted site at ramblingmoose.wordpress.com as a backup.

I really don’t care for how my WordPress site looks, so I want to change it.  Being someone with more years in IT Software Development Project Management than I care to admit to, I will do it “offline” and not on the live site.

Furthermore, I have a client in Los Angeles.  His website was developed on WordPress by me, and I have a backup.  I’m finished with the site, but I thought it might be “fun” to see if I could get it to work here on my own computer.

The reasoning:

My own main computer running Debian I am happy with.  Actually that is an understatement.  I don’t want to slow it down by loading up server software, a LAMP stack, and things to slow it all down.   I could create a VMWare or Virtual Box virtual computer and do the LAMP stack there, I’ve done that a couple times before, but running a full VM for something like this felt “overkill” and “heavyweight”.

What Docker Does:

Docker will allow me to share some of my computer by running a pared down version of Linux inside what they call a Container.  It is not a full virtual computer, so it should run faster, and since it is not a full computer it will not effect my apparent speed – in case I forget to “turn the damn thing off at night”.

The Goal:

Get a Docker Container up and running.  The container will have a web server and WordPress software running configured for my use.


 

Installing Docker:

This is adapted from the official Docker instructions found at this link.

This will get the base Docker software installed on a Debian system.  Your system should be “up to date”.  It should be running fairly current software.  As I am writing this March 2017, Docker will run on Debian 7, 8, and 9.  9 being “Stretch” or “Testing” at this point, 8 being “Jessie”, and 7 is “Wheezy”.

My own personal thought is that if you aren’t running at least “Jessie”, get yourself upgraded to current software.  After all, within a month or three of this writing, Stretch will become “Stable” and the official up to date current software.  It’s easy.  I started with Wheezy, migrated to Jessie, and am currently running Stretch.

Open a terminal session and sign in as root with “su”.

Add transport module to allow Docker to grab what it needs via HTTPS:

Add the Docker GPG key:

curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add –
Verify that the key ID is 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88.

apt-key fingerprint 0EBFCD88

pub   4096R/0EBFCD88 2017-02-22
Key fingerprint = 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid                  Docker Release (CE deb) <docker@docker.com>
sub   4096R/F273FCD8 2017-02-22

Add the Docker repository:

add-apt-repository \
“deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable”

Update your apt repository lists:

apt update

 Install Docker:

apt install docker-ce

 

At this point, Docker is installed.  They set up a container that you can run to verify it called Hello World.

docker run hello-world

Docker is installed.  The software will run from the command line, as root.  It can be configured to start automatically by entering in a command:  

systemctl enable docker

However I have not yet done it because I am not convinced I want to run this every time I boot.  I am being conservative with my system resources, but to be honest I have not noticed it slowing me down in the slightest.   Since I will only be running this intermittently,  I probably will not be running it.

Since this tends to be my own mental scratch pad, the way to disable docker at boot is:

systemctl disable docker

This and more tweaks to how it runs are found at Docker’s own help file for post install.

Conclusion:

Obviously, this is something that is incomplete.  I will be returning with more when I go to get my container started.  I need a Container with Debian, a LAMP Stack, and WordPress.  A ready made version of this exists, and I will try that first – ready made from Docker itself!

On the other hand, my own normal IT Project Management curiosity tells me that I need to make one on my own.  So I’ll work on that later.

First step, getting it installed, worked.  Next I will get onto that other stuff… later.