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

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,



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:

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.


1 Like

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 …

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.

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.

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 script is still installing the default WordPress directory in /var/www/html.


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.

quite surprising that such question remain unasolved.

1 Like