How to Connect and Edit Configuration Files for WordPress Running on Linux in a Docker Container Includes Changing Site URL


Thought Leadership & Events

 

Here are the steps.

 

1) ssh to the linux host  (using SSH or Putty, or whatever)

change to Super User

sudo su

   enter su credentials if required.  If you cannot switch to su mode, then just add sudo in front of all the below commands.

2) confirm docker is running… Display a list of all containers…

Docker Info

Docker ps  –a

image

Notice the ID of the container that you want to connect to: Is it running?  If not you can start it with:

    Docker Start <ContainerID>

Since the container is running wordpress (or other web engine) it will not have an interactive session attached to it.  To create a new interactive 

    docker exec –it <ContainerID>  bash

image

You will then get a new prompt and automatically dropped into /var/www/html  Notice your prompt changed Smile

ls

You will now see a list of the files and folders

image

 

You can now show a list of the environment variables with

printenv

imagec

 

You can now search for the files you want to edit using find <DirectoryName> –name <FileName>

see more about find at https://www.cyberciti.biz/faq/how-do-i-search-my-linuxunix-server-for-a-file/

If you wanted to search for functions.php file..

 

find . –name functions.php

image

 

I do not have an editor installed yet so I will install VIM

apt-get update

apt-get install vim

image

[Optional], add more features to VIM (aka: vi):  

    apt-get install vim-scripts vim-doc vim-latexsuite vim-gui-common

Long screenshot so skipping…

 

See http://itproguru.com/expert/2016/11/how-to-exit-quit-vi-editor-without-saving-changes-step-by-step/ for step by step instructions on how to exit with or without saving your file using VIM (aka: vi)

 

vim <filename.ext>

I am going to make a change in wp-config.php

vi wp-config.php

image

I want to change the URL of my site so I am adding

 

define('WP_HOME','http://example.com');

define('WP_SITEURL','http://example.com');

I also added a comment as you can see in the image.  The forward slash is a special character so

you need to add it after some text, then just delete the text.

image

 

<Escape> then :wq! to save changes

cat wp-config.php   then scroll up to see my changes in the file

 

To Exit out of the container…

exit

 

you can also check the status of the container and restart it.

image

 

 

to exit out of ssh type

exit

 

see also http://itproguru.com/expert/2016/10/docker-create-container-change-container-save-as-new-image-and-connect-to-container/ for more help on docker