如何在Windows 10家庭版上运行Docker

Recently I have been watching a tutorial where, in order to follow it, you need to have Docker running on your machine. So far, so good.

最近,我一直在观看一个教程,为了跟随它,您需要在机器上运行Docker 。 到目前为止,一切都很好。

But it turns out that the latest versions of Docker require Windows 10 Pro, Enterprise, or Education. Which means that if you are like me and have just Windows 10 Home edition on your personal laptop, then you cannot use Docker…or maybe you still can.

但是事实证明,最新版本的Docker需要Windows 10 Pro,Enterprise或Education。 这意味着,如果您像我一样,并且在个人笔记本电脑上只有Windows 10 Home Edition,那么您将无法使用Docker… 也许仍然可以

Read on below to find out how. 📑

请在下面继续阅读,以了解操作方法。 📑

推理 (Reasoning)

First, let's do a short summary of the situation. What do we want to achieve and what do we currently have?

首先,让我们对情况做一个简短的总结。 我们想要实现什么,我们目前拥有什么?

We have Windows 10 OS Home edition on our machine. We would like to have Docker running on the same machine so that we are able to create docker images, run containers, and learn better and grow faster!

我们的计算机上装有Windows 10 OS Home Edition。 我们希望Docker在同一台机器上运行,以便我们能够创建Docker映像,运行容器,并更好地学习和更快地发展!

The last one is a bit out of the scope of this article, but we should start from somewhere, no? 😏.

最后一个有点超出了本文的范围,但是我们应该从某个地方开始,不是吗? 😏。

动作 (Actions)

After defining what we want, let's see how to achieve it. Here are the steps I followed. It worked for me, which make me want to share it with you. And maybe I can save someone a few days of going back and forth to StackOverflow! 😐

在定义了我们想要的东西之后,让我们看看如何实现它。 这是我遵循的步骤。 它对我有用,这使我想与您分享。 也许我可以节省一些人来回StackOverflow的时间! 😐

After some reading, I found this article. It explains that it is possible to use Docker in Windows 10 Home by leveraging a Linux virtual machine and having Docker containers running on it. Let's see how it works.

经过一番阅读,我找到了这篇文章 。 它解释说,可以通过利用Linux虚拟机并在其上运行Docker容器来在Windows 10 Home中使用Docker。 让我们看看它是如何工作的。

步骤1:安装 (Step 1: Installations)

First you need to install a software called Oracle VM VirtualBox. It gives you the ability to have multiple virtual machines installed on your physical one. This way we can have a virtual machine which will be running Linux where our Docker will live.

首先,您需要安装一个名为Oracle VM VirtualBox的软件。 它使您能够在物理计算机上安装多个虚拟机。 这样,我们就可以拥有一个将运行Docker的Linux虚拟机。

Then use Windows PowerShall and Chocolatey, your Windows package manager, to install a docker-machine by running the following:

然后使用Windows PowerShall和Chocolate包(您的Windows包管理器)通过运行以下命令来安装docker-machine

choco install docker-machine

Open your favorite bash terminal app and run this:

打开您喜欢的bash终端应用程序并运行以下命令:

docker-machine create --driver virtualbox default

This will create a docker virtual machine called 'default'.

这将创建一个名为“默认”的码头工人虚拟机。

步骤2:配置 (Step 2: Configurations)

Next, we need to configure which ports are exposed when running Docker containers. You can do that by going to Oracle VM VirtualBox -> default virtual machine -> Settings -> Network -> Adapter 1 -> Port Forwarding.

接下来,我们需要配置在运行Docker容器时公开哪些端口。 您可以通过以下操作来实现:转到Oracle VM VirtualBox->默认虚拟机->设置->网络->适配器1->端口转发。

This was the most critical detail that I forgot . We need to allow Docker to mount volumes located on your hard drive. By default, you can only mount from the C://Users/ directory.

这是我忘记的最关键的 细节 。 我们需要允许Docker挂载位于您的硬盘驱动器上的卷。 默认情况下,您只能从C://Users/目录挂载。

To add a different path, simply go to the Oracle VM VirtualBox GUI. Select default VM and go to Settings > Shared Folders. If you don't mind to use the default settings, do not forget to put your project under the 'Users' directory, e.g. C:\Users\{your project}.

要添加其他路径,只需转到Oracle VM VirtualBox GUI。 选择默认 VM,然后转到“设置”>“共享文件夹” 。 如果您不介意使用默认设置,请不要忘记将您的项目放在“用户”目录下,例如C:\Users\{your project}

In my case, I forgot about this and had to spend few days of head banging until I figured out why the heck was I getting a "Couldn't find package.json" error when trying to run the containers, built through this tutorial.

就我而言,我忘记了这一点,不得不花了几天的脑袋,直到我弄清楚为什么在尝试运行通过本教程构建的容器时 ,为什么会遇到“无法找到package.json”错误。

Start the virtual machine by running the following command in your terminal app:

通过在终端应用程序中运行以下命令来启动虚拟机:

docker-machine start default

步骤3:设置环境变量 (Step 3: Setting up Environment Variables)

Next, we need to set up Docker environment variables:

接下来,我们需要设置Docker环境变量:

docker-machine env default

This allows the Docker client and Docker Compose to communicate with the Docker Engine running in the Linux VM that we named "default".

这允许Docker客户端和Docker Compose与在我们称为“默认”的Linux VM中运行的Docker Engine通信。

You may also need to run:

您可能还需要运行:

@FOR /f "tokens=*" %i IN ('"C:\ProgramData\chocolatey\lib\docker-machine\bin\docker-machine.exe" env') DO @%i

in order to get Docker working properly. Note: the specified path in the above command may vary depending on your setup.

为了使Docker正常工作。 注意:以上命令中指定的路径可能会因您的设置而异

If you are going to use things such as docker-compose up, you will need to install Docker Tools as well. You may do it by running the following commands in PowerShall:

如果要使用docker-compose up工具,则还需要安装Docker Tools。 您可以通过在PowerShall中运行以下命令来执行此操作:

choco install docker-cli
choco install docker-compose

These will install everything you need to start using Docker on your Windows 10 Home OS.

这些将安装在Windows 10 Home OS上开始使用Docker所需的一切。

结论 (Conclusion)

Now that we have all we need, we may spend our time on actual learning, either by following a docker-related tutorial or reading a book. No matter what you want to do next, you have all the tools you will need.

现在我们有了所需的一切,我们可以花时间在实际学习上,方法是关注与Docker相关的教程或阅读一本书。 无论接下来要做什么,您都将拥有所需的所有工具。

I personally will try to finish the previously mentioned tutorial and then, who knows, may be I will start using Docker for each project I do.

我个人将尝试完成前面提到的教程,然后,谁知道呢,也许我将开始为我所做的每个项目使用Docker。

By the way, during the process of researching, I found a very promising book which is specifically about Docker. It's called "Docker in Practice" by Ian Miell. If this interests you, you might want to take a look.

顺便说一下,在研究过程中,我发现了一本非常有前途的书,专门针对Docker。 它被Ian Miell称为“实践中的Docker” 。 如果您对此感兴趣,则可能需要看看。

🔥 Thanks for reading! 🔥

🔥感谢您的阅读! 🔥

参考文献 (References)

翻译自: https://www.freecodecamp.org/news/how-to-run-docker-on-windows-10-home-edition/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值