0

I have a Wordpress installation running in a Docker instance. I'm having a problem with e-mail and it's likely due to sendmail missing. If indeed I have to add sendmail to the container, what is the intended way to do this? I've seen the lxc hacks but it's always stated or at least implied that this isn't within the intentions of how Docker is supposed to work. I decided on Docker for my Wordpress site because I already had a running system with HTTP services installed and the idea of basically sectioning off everything (Apache, PHP, MySQL, etc.) really appealed to me. I can then just backup the whole container and move it to another system in entirety if need be.

To state my question as directly as possible, what method of modifying a running container is most appropriate for the intended design of Docker? Should I just attempt the ad-hoc bash prompt via lxc-attach as mentioned above? Or is there a more appropriate way like making the container a new image (to preserve all my WP data) and modifying the image and then re-starting the container?

Community
  • 1
  • 1
Matt Molnar
  • 2,412
  • 3
  • 22
  • 28
  • Does Wordpress have the option to send mail from another SMTP server? It may be best to add a new container with an SMTP server running and make Wordpress talk to that. – Marcus Hughes Jul 29 '14 at 08:11
  • I thought about SMTP but figured it was the same work to install that in a running container, didn't think about adding a new one though, might have to try that. – Matt Molnar Jul 29 '14 at 12:37

1 Answers1

2

Long answer:

I'd recommend changing the way your project is structured.

Having a database inside your container is okay for local development - when you don't care if the changes you make are lost every time you restart your container.

At the moment, if your container dies for any reason, or if you need to restart it for any reason, your data will be lost.

Using nsenter (mentioned below) to attach to your running container when you need to:

  • Install mysql on your host machine
  • Attach to your running container and do a mysqldump of your database
  • scp your .sql file from your container to your host
  • Import your database into mysql on the host
  • Point your Wordpress site to the hosts database

The way I look at whether or not my Docker projects are set up correctly is this:

If you can't get back to where your container currently is at the moment in an automated fashion, you're doing something wrong.

Short answer:

Use nsenter to attach to your container and make the changes you need.

And pray that nothing goes wrong with your container so you don't lose your data.

Chris McKinnel
  • 14,694
  • 6
  • 64
  • 67
  • An alternative to having `mysql` installed on your host is having your mysql data directory mounted to a folder on your host so it persists across container restarts. – Chris McKinnel Jul 29 '14 at 09:21
  • So Docker should really just be used to sort of package applications for a given service but not actually contain the data for those services? – Matt Molnar Jul 29 '14 at 12:42
  • Exactly, docker is designed to package applications and their dependencies. – Chris McKinnel Jul 29 '14 at 13:52
  • I should have gave an example of using nsenter: `sudo nsenter -t $(docker inspect --format '{{ .State.Pid }}' CONTAINER_ID) -m -u -i -n -p -w` – Chris McKinnel Jul 29 '14 at 15:32