简体   繁体   English

如何创建自定义 docker 镜像?

[英]How do i create a custom docker image?

I have to deploy my application software which is a linux based package (.bin) file on a VM instance.我必须在 VM 实例上部署我的应用程序软件,它是基于 linux 的包 (.bin) 文件。 As per system requirements, it needs minimum 8vCPUs and 32GB RAM.根据系统要求,它至少需要 8vCPU 和 32GB RAM。

Now, i was wondering if it is possible to deploy this software over multiple containers that load share the CPU and RAM power in the kubernetes cluster, rather than installing the software on a single VM instance.现在,我想知道是否可以将这个软件部署在多个容器上,这些容器负载共享 kubernetes 集群中的 CPU 和 RAM 功率,而不是在单个 VM 实例上安装该软件。

is it possible?是否可以?

Yes, it's possible to achieve that.是的,这是有可能实现的。

You can start using docker compose to build your customs docker images and then build your applications quickly.您可以开始使用 docker compose 来构建您的自定义 docker 镜像,然后快速构建您的应用程序。

First, I'll show you my GitHub docker-compose repo , you can inspect the folders, they are separated by applications or servers, so, one docker-compose.yml build the app, only you must run a command docker-compose up -d首先,我将向您展示我的 GitHub docker-compose repo ,您可以检查文件夹,它们由应用程序或服务器分隔,因此,一个docker-compose.yml构建应用程序,只需运行命令docker-compose up -d

if you need to create a custom image with docker you should use this docker command docker build -t <user_docker>/<image_name> <path_of_files>如果您需要使用docker build -t <user_docker>/<image_name> <path_of_files>创建自定义图像,则应使用此docker build -t <user_docker>/<image_name> <path_of_files>命令docker build -t <user_docker>/<image_name> <path_of_files>

<user_docker> = your docker user <user_docker> = 您的<user_docker>用户

<image_name> = the image name that you choose <image_name> = 您选择的图像名称

<path_of_files> = somelocal path, if you need to build in the same folder you should use . <path_of_files> = 某个本地路径,如果您需要在同一文件夹中构建,则应使用 . (dot) (点)

So, after that, you can upload this image to Dockerhub using the following commands.因此,之后,您可以使用以下命令将此图像上传到 Dockerhub。

You must login with your credentials您必须使用您的凭据登录

docker login

You can check your images using the following command您可以使用以下命令检查图像

docker images 

Upload the image to DockerHub registry将镜像上传到 DockerHub 注册中心

docker push <user_docker>/<image_name>

Once the image was uploaded, you can use it in different projects, make sure to make the image lightweight and usefully上传图像后,您可以在不同的项目中使用它,确保图像轻巧且有用

Second, I'll show a similar repo but this one has a k8s configuration into the folder called k8s.其次,我将展示一个类似的存储库,但这个存储库在名为 k8s 的文件夹中有一个 k8s 配置。 This configuration was made for Google cloud but I think you can analyze it and learn how you can start in your new project.此配置是为 Google Cloud 设计的,但我认为您可以对其进行分析并了解如何开始新项目。

The Nginx service was replaced by ingress service ingress-service.yml and https certificate was added certificate.yml and issuer.yml filesNginx服务替换为 ingress 服务ingress-service.yml并添加https certificate certificate.ymlissuer.yml文件

If you need dockerize dbs, make sure the db is lightweight, you need to make a persistent volume using PersistentVolumeClaim (database-persistent-volume-claim.yml file) or if you use larger data onit you must use a dedicated db server or some db service in the cloud.如果您需要 dockerize dbs,请确保 db 是轻量级的,您需要使用PersistentVolumeClaim (database-persistent-volume-claim.yml 文件)制作一个持久卷,或者如果您使用更大的数据,则必须使用专用的 db 服务器或一些db 服务在云端。

I hope this information will be useful to you.我希望这些信息对你有用。

There are two ways to achieve what you want to do.有两种方法可以实现您想做的事情。 The first one is to write a dockerfile and create the image.第一个是写一个dockerfile并创建镜像。 More information about how to write a dockerfile can be found from here .可以从这里找到有关如何编写 dockerfile 的更多信息。 Apart for that you can create a container from a base image and install all the software and packages and export it as a image.除此之外,您可以从基础镜像创建一个容器并安装所有软件和包并将其导出为镜像。 Then you can upload to a docker image repo like Docker Registry and Amazon ECR然后你可以上传到 Docker 镜像仓库,比如 Docker Registry 和 Amazon ECR

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

相关问题 如何使用 Jenkins 管道从 docker-compose 创建 docker 映像? - How can I use a Jenkins pipeline to create a docker image from docker-compose? 如何在 Azure 中为自定义域创建证书? - How do I create certificates in Azure for a custom domain? 如何构建代表 Azure 数据湖(第 2 代)的 Docker 映像? - How do I build a Docker image representing Azure's Data Lake (gen 2)? 如何创建/连接到 Docker Azure 服务总线(使用 Python SDK)? - How do I create/connect to a Docker Azure service bus (using Python SDK)? 如何在Azure App Service Linux上安装自定义Docker映像的文件夹 - How to mount folder for custom docker image on Azure App Service Linux Azure 批处理池:如何通过 Python 使用自定义 VM 映像? - Azure Batch Pool: How do I use a custom VM Image via Python? 尝试创建 docker 容器 function 应用程序,当我执行 docker 运行时出现错误“未定义存储” - Trying to create docker container function app, when i do docker run getting the error “Storage not defined” 如何使用 Packer + Terraform 创建小于 30GB 的自定义 Azure 映像? - How do I create custom Azure images smaller than 30GB with Packer + Terraform? 如何使用Azure ARM创建公共虚拟机映像? - How do I create a public virtual machine image using Azure ARM? 如何在 Azure Web 应用程序中运行自定义“docker”命令? - How I to run custom "docker" command in Azure Web Application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM