Docker Community Forums

Share and learn in the Docker community.

How to port an existing wordpress site to a docker container?

docker

(Haemse) #1

I have a wordpress site running on a debian vps and apache. I have just read a view docker tuts. They all go with a preexisting docker image for wordpress and set up a completely new site.

But how do I port my existing wordpress site into a docker container?

And even more important. How am I able to continue developing on this site? How can I access the files and db inside that docker container over ssh, sftp etc. ??? How is this issue generally solved?

Please bring some light into my dark, thanks,

haemse


(Jeff Anderson) #2

Hello,

The official wordpress image mounts a volume and looks for the presence of wordpress there. If it doesn’t find wordpress, it will try to download the latest wordpress and install it.

If you want to use the wordpress container with an existing site, just import the site to the volume.

There are a few other things that the wordpress container does to a new installation that may get skipped when you import an existing install. Take a look at the wordpress entrypoint script to see what it does: https://github.com/docker-library/wordpress/blob/master/docker-entrypoint.sh

Particularly, the bits that change the wordpress config to look at environment variables for database credentials are essential.

The wordpress container doesn’t include an ssh daemon directly. You could put the wordpress installation into a host mounted volume and then use the docker host’s ssh for ssh/sftp.

Cheers!


(Haemse) #3

Thanks for the answer!

So with the official image the SQL db ist inside the container, but files are outside?

In principle could I also use another container (with SSH/SFTP deamon) that mounts the wp directory and use it to develope the site? Would be easier if I wanna migrate the whole server I would not need to conf all the ssh users and stuff … I wonder if there would be any folder/file permission issues …


(Jeff Anderson) #4

No, the official image looks at environment variables to see the database connection info. By default wordpress doesn’t do this, so the official wordpress image has to update the config to look at the environment.


(Jeff Anderson) #5

You wouldn’t need another container for ssh/sftp if your host is running ssh/sftp and you use a host-mounted volume instead of a regular volume.


(Dockerdancab) #6

I’m trying to do a migration as well. I’m mounting a volume via AWS EC2 service to /var/www/html in the Docker container. My mount has my complete WordPress installation with wp-config.php, wp-content, etc.

The mount seems to work as expected but the entrypoint.sh script is still installing the default WordPress directory in /var/www/html.

Thoughts??


(Sapetnioc) #7

I also tried to move an existing site to a Docker container. In order to make files in /var/wwww/html accessible to wordpress, I had to change their ownership to www-data. For my tests, I choosed to do a chown on the host file system since www-data has the same uuid both in host and Docker.

I want to make the site usable from the host (exporting the database, changing URLs and paths in SQL and copying files and importing database in Docker). Unfortunately, the site served via Docker is broken. If I ever succeed, I will post my recipe.


(Deemx) #8

quite surprising that such question remain unasolved.