简体   繁体   English

了解 Docker 以提供 web、mysql 或类似服务

[英]Understanding Docker for providing services like web, mysql or similar

I have several questions regarding Docker.我有几个关于 Docker 的问题。

First my project: I have a blog on a shared host and want to move it to the cloud to have all the server sides in my hands and to have the possibility to scale my server on my needs.首先是我的项目:我在共享主机上有一个博客,并希望将其移动到云中以将所有服务器端掌握在我手中,并有可能根据我的需要扩展我的服务器。

My first intend was to setup a nice ubuntu 14 lts as a server with nginx, php 7 and mysql.我的第一个打算是使用 nginx、php 7 和 mysql 设置一个不错的 ubuntu 14 lts 作为服务器。 But I think it's not that easy to transfer such a server to another cloud ie from gce to aws.但我认为将这样的服务器转移到另一个云并不容易,即从 gce 转移到 aws。 I then thought about using docker, as a friend told me how easy it is to setup containers and how easy it is to move them from one server to another.然后我考虑使用 docker,因为一位朋友告诉我设置容器是多么容易,以及将它们从一个服务器移动到另一个服务器是多么容易。

I then read a lot about docker but stumbled upon a few things I wondered about.然后我阅读了很多关于 docker 的内容,但偶然发现了一些我想知道的事情。

In my understanding docker runs just services like php, mysql or similar, but doesn't hold data, right?据我了解,docker 只运行 php、mysql 或类似服务,但不保存数据,对吗? Where would I store all the data like database, nginx.conf, php.ini and all the Files I want to serve with nginx (ie. /var/www/)?我将在哪里存储所有数据,如数据库、nginx.conf、php.ini 以及我想与 nginx 一起使用的所有文件(即 /var/www/)? Are they stored on the host system?它们是否存储在主机系统上? If yes, it would not be easier to move a docker setup then move a whole server, no?如果是,那么移动 docker 设置然后移动整个服务器不会更容易,不是吗?

Do I really have an advantage of using Docker to serve a Wordpress Blog or another Website using MySQL and so on?我真的有使用 Docker 为 Wordpress 博客或其他使用 MySQL 等网站提供服务的优势吗?

Thanks in advance提前致谢

Your data is either stored on the host machine or you data is attached to the docker containers remotely (using a network-attached block device).您的数据要么存储在主机上,要么您的数据远程附加到 docker 容器(使用网络附加块设备)。

When you store your data on the host machine, you have a number of options.当您将数据存储在主机上时,您有多种选择。

  1. The data can be 'inside' one of your containers (eg your mysql databases live inside your mysql container).数据可以在您的容器之一的“内部”(例如,您的 mysql 数据库位于您的 mysql 容器内)。

  2. You can mount one or more directories from your host machine inside your containers.您可以在容器内从主机挂载一个或多个目录。 So then the data lives on your host.那么数据就存在于您的主机上。

  3. You can create Docker volumes or Docker volume containers that are used to store your data.您可以创建用于存储数据的 Docker 卷或 Docker 卷容器。 These volumes or volume containers are mounted inside the container with your application.这些卷或卷容器与您的应用程序一起安装在容器内。 The data then lives in directories managed by Docker.然后数据位于由 Docker 管理的目录中。

For details of these options, see dockervolumes有关这些选项的详细信息,请参阅dockervolumes

  1. The last option is that you mount remote storage to your docker containers.最后一个选项是将远程存储挂载到 docker 容器。 Flocker is one of the options you have for this. Flocker是您对此的选择之一。

At my work I've set up a host (ie server) that runs a number of services in docker containers.在我的工作中,我设置了一个在 docker 容器中运行许多服务的主机(即服务器)。 The data for each of these services 'lives' in a Docker data volume container.这些服务中的每一个的数据都“存在”在 Docker 数据卷容器中。

This way, the data and the services are completely separated.这样,数据和服务就完全分离了。 That allows me to start, stop, upgrade and delete the containers that are running my services without affecting the data.这允许我启动、停止、升级和删除运行我的服务的容器而不影响数据。

I have also made separate Docker containers that are started by cron and these back up the data from the data volume containers.我还制作了由cron启动的单独 Docker 容器,这些容器从数据卷容器中备份数据。

For mysql, the backup container connects to the mysql container and executes mysqldump remotely.对于mysql,备份容器连接到mysql容器,远程执行mysqldump

I can also run the (same) containers that are running my services on my development machine, using the data that I backed up from the production server.我还可以使用我从生产服务器备份的数据运行在我的开发机器上运行我的服务的(相同)容器。

This is useful, for instance, to test upgrading mysql from 5.6 to 5.7.例如,这对于测试将 mysql 从 5.6 升级到 5.7 很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM