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!