您(Are)是一名开发人员并开始使用容器化吗?容器(Containerization)化是当今的新趋势,它使您现有的应用程序系统独立且更可靠。如果您只是一个初学者并开始使用Docker等工具,那么这里就是您的最佳选择。在这篇文章中,我们介绍了如何在Windows机器上设置和使用Docker的教程。(Docker)该过程假设您对容器化的概念有些熟悉。
为了给你一个更清晰的容器定义,我直接引用Docker:
A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.
(Set)在Windows上(Windows)设置和使用Docker 桌面(Docker Desktop)
Docker有很多用例。其中最受欢迎的是现有应用程序的容器化。您可以将现有Java或 .NET 应用程序重新打包到可部署到任何服务器的高度可移植容器中。但要做到这一点,你需要了解它的基础知识。那么让我们开始吧,看看如何在Windows上进行设置。
1. 下载并安装设置。前往 Docker 的网站并下载Docker Desktop for Windows。下载后,按照设置中的简单说明将其安装到您的计算机上。在此过程中,您的计算机可能会重新启动几次。
2. 一切安装完毕后,您需要创建一个帐户。前往 hub.docker.com 并创建一个新帐户。现在使用相同的帐户登录到您在Windows上的安装。创建帐户是完全免费的,您不会被收取任何费用。
3.设置部分到此结束。您可以通过转到系统托盘并单击鲸鱼图标来确认Docker是否正在运行。(Docker)或者你可以打开一个CMD窗口并执行
docker --version
检查您的计算机上是否安装了Docker 。或者,您也可以下载hello-world映像以检查一切是否正常。在同一个CMD窗口中执行 docker run hello-world 来运行所有的检查。
4. 现在你需要一个镜像来启动你的第一个容器。有许多用于不同目的的公共图像。您可以转到Docker中心并搜索您想要的任何图像。有可用于WordPress、Ubuntu、Node.Js等的图像。在本例中,我们将在本地容器上安装WordPress图像,以便您可以在计算机上运行本地WordPress容器。
5. 创建任何容器的第一步是创建其配置文件。配置文件指定容器将使用什么图像以及带有什么参数。因此,创建一个新文件夹并在该文件夹内创建一个名为docker-compose.yml 的新文件。(docker-compose.yml.)将以下内容粘贴到其中并保存文件:
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
db_data: {}
资料来源:Docker 文档
6.在这个文件夹中打开一个CMD窗口并执行
docker-compose up -d
开始下载图像并在本地计算机上设置容器。命令完成执行后,您将在本地计算机上启动并运行一个WordPress容器。(WordPress)http://localhost:8000在浏览器中打开它。
这就是您如何创建配置文件,然后下载在容器中运行应用程序所需的内容。请记住(Remember),还有很多其他的可能性,这篇文章只是为了给你一个关于Docker和容器化的概述。您可以在 Internet 上搜索更多配置文件,甚至可以创建自己的配置文件。网上有很多免费的开源Docker镜像可以帮助您入门。
自定义映像并进行必要的更改后,您还可以将其推送到Docker Hub存储库。单击(Click) 此处(here)(here)下载适用于Windows的(Windows)Docker 桌面(Docker Desktop)。在此处(here)(here)进一步(Further)阅读有关Docker for Windows的信息。
How to set up and use Docker Desktop on Windows
Are you a developer and getting started wіth containerization? Containerization is the new trend these days and it makes your existing application system-independent and more reliable. If you are just a beginner and getting started with tools like Docker, then this is the right place to be at. In this post, we have covered a tutorial on how to set up and use Docker on a Windows machine. The process assumes that you are somewhat familiar with the concept of containerization.
To give you a clearer definition of a container, I would directly like to quote Docker:
A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.
Set up & use Docker Desktop on Windows
Docker has quite a lot of use case. The most popular of them being containerization of existing applications. You can repackage your existing Java or .NET applications in a highly portable container that can be deployed to any server. But to do that, you need to get through the basics of it. So let’s get started and see how to set it up on Windows.
1. Download and install the setup. Head over to Docker’s website and download Docker Desktop for Windows. Once downloaded, install it on your computer by following the simple instructions in the setup. Your computer might restart a few times during the process.
2. Once everything is installed, you need to create an account. Head over to hub.docker.com and create a new account. Now use the same account to login into you installation on Windows. Creating an account is totally free and you won’t be charged anything.
3. The setup part is now over. You can confirm if Docker is running by going to system tray and clicking on the whale icon. Or you can open a CMD window and execute
docker --version
to check if you have Docker installed on your computer. Or you can also download the hello-world image to check if everything is working fine. In the same CMD window execute docker run hello-world to run all the checks.
4. Now you need an image to start your first container. There are a lot of public images available for different purposes. You can go to Docker hub and search for any image that you would like. There are images available for WordPress, Ubuntu, Node.Js etc. In this example, we are going to install a WordPress image on a local container so that you can run a local WordPress container on your computer.
5. The first step of creating any container is creating its configuration file. The configuration file specifies what image the container will use and with what parameters. So, create a new folder and inside that folder create a new file called docker-compose.yml. Paste the following contents into it and save the file:
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
db_data: {}
Source: Docker Documentation
6. Open a CMD window in this folder and execute
docker-compose up -d
to start downloading the images and setting up the container on your local machine. Once the command finishes execution, you will have a WordPress container up and running on your local machine. You can open it up in your browser by going to http://localhost:8000.
This was how you can create a configuration file and then download the required things for running your application inside a container. Remember that, there are tons of other possibilities available and this post is here to only give you an overview of Docker and containerization. You can search the internet for more configuration files or you can even create your own. There are a lot of free open-source Docker images available online that can get you started.
Once you’ve customized your image and made the necessary changes, you can also push it to a Docker Hub repository. Click here to download Docker Desktop for Windows. Further reading about Docker for Windows here.