translated

This commit is contained in:
geekpi 2022-08-24 08:35:52 +08:00
parent ccf53b945d
commit 37ebcec533
2 changed files with 111 additions and 111 deletions

View File

@ -1,111 +0,0 @@
[#]: subject: "Convert Docker Run Commands Into Docker-Compose Files"
[#]: via: "https://ostechnix.com/convert-docker-run-commands-into-docker-compose-files/"
[#]: author: "sk https://ostechnix.com/author/sk/"
[#]: collector: "lkxed"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Convert Docker Run Commands Into Docker-Compose Files
======
Create Docker compose files from docker run commands using Composerize
If you use Docker everyday in your official or personal systems, you should know there is an useful application called **Composerize**. In this brief guide, we will learn what is Composerize and how to use Composerize to **convert docker run commands into docker-compose files** format in Linux.
### What Is Composerize?
**[Docker compose][1]** is a tool for defining and running multi-container docker applications. Docker compose is just a YAML file in which we define services, networks, and volumes for a Docker application.
Not everyone is good at writing effective docker-compose files. Some of you may find it difficult to even write a simple docker compose file. No worries! Say hello to Composerize utility, which helps you to create Docker compose files from `docker run` commands.
Composerize is a command line as well as web-based utility to convert a `docker run` command into a docker-compose file.
It doesn't matter whether the `docker run` command is simple, short or lengthy and complex. All you have to do is just pass thecommand to Conposerize. Composerize will instantly turn the `docker run` commands into docker-compose files!
### Install Composerize In Linux
Composerize is available as a web service. So you don't have to install it on your system. If you want to install it locally for any reason, read on.
Composerize can be installed using npm. Make sure you've installed Nodejs in your system. If it is not installed, follow the link below to install Nodejs.
* [How To Install NodeJS On Linux][2]
After installing Nodejs, run the following command to install Composerize:
```
$ npm install composerize
```
This command will install Composerize for the current user only.
If you want to install it globally (system-wide), run the above command with `-g` option like below.
```
$ npm install composerize -g
```
### Convert Docker Run Commands Into Docker-Compose Files With Composerize
To convert a docker run command into docker-compose format, simply run it with Composerize like below:
```
$ composerize docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer
```
It will generate the content in docker compose file format.
**Sample output:**
```
version: '3.3'
services:
portainer:
ports:
- '9000:9000'
volumes:
- '/var/run/docker.sock:/var/run/docker.sock'
image: portainer/portainer
```
![Convert Docker Run Commands Into Docker-Compose Files With Composerize][3]
Now copy the above lines in your `docker-compose.yml` file. It's that simple!
As I stated already, you can also use the Composerize web service to convert the docker run commands into docker file format.
Go to **[https://www.composerize.com/][4]** link and paste the `docker run` command in the box and you will get the docker-compose file instantly!
![Turn Docker Run Commands Into Docker-compose Files Using Composerize][5]
After converting the commands in docker-compose file, go to the location where you saved the `docker-compose.yml` file and run the following command to start the Docker application:
```
$ docker-compose up
```
Composerize is one of the useful utility for Docker users. You can now safely say goodbye to sprawling docker commands.
**Resource:**
* [Composerize GitHub Repository][6]
--------------------------------------------------------------------------------
via: https://ostechnix.com/convert-docker-run-commands-into-docker-compose-files/
作者:[sk][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://ostechnix.com/author/sk/
[b]: https://github.com/lkxed
[1]: https://ostechnix.com/introduction-to-docker-compose/
[2]: https://ostechnix.com/install-node-js-linux/
[3]: https://ostechnix.com/wp-content/uploads/2022/08/Convert-Docker-Run-Commands-Into-Docker-Compose-Files-With-Composerize.png
[4]: https://www.composerize.com/
[5]: https://ostechnix.com/wp-content/uploads/2022/08/Turn-Docker-Run-Commands-Into-Docker-compose-Files-Using-Composerize.png
[6]: https://github.com/magicmark/composerize

View File

@ -0,0 +1,111 @@
[#]: subject: "Convert Docker Run Commands Into Docker-Compose Files"
[#]: via: "https://ostechnix.com/convert-docker-run-commands-into-docker-compose-files/"
[#]: author: "sk https://ostechnix.com/author/sk/"
[#]: collector: "lkxed"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
将 Docker 运行命令转化为 Docker-Compose 文件
======
使用 Composerize 从 docker 运行命令创建 Docker compose 文件
如果你每天在官方或个人系统中使用 Docker你应该知道有一个有用的应用叫 **Composerize**。在这个简短的指南中,我们将了解什么是 Composerize以及如何使用 Composerize 在 Linux 中**将 docker 运行命令转换为 docker-compose 文件**格式。
### 什么是 Composerize
**[Docker compose][1]** 是一个用于定义和运行多容器 docker 应用的工具。Docker compose 只是一个 YAML 文件,我们在其中为 Docker 应用定义服务、网络和卷。
不是每个人都擅长写有效的 docker-compose 文件。你们中的一些人可能会发现,甚至写一个简单的 docker compose 文件都很困难。不用担心! 看下 Composerize它可以帮助你从 `docker run` 命令中创建 Docker compose 文件。
Composerize 是一个命令行和基于网络的工具,可以将 `docker run` 命令转换成 docker-compose 文件。
无论 `docker run` 命令是简单、简短还是冗长、复杂,都没有关系。你所要做的就是把命令传给 Conposerize。Composerize 会立即将 `docker run` 命令变成 docker-compose 文件!
### 在 Linux 中安装 Composerize
Composerize 是作为一个网络服务提供的。所以你不需要在你的系统上安装它。如果你因为任何原因想在本地安装它,请继续阅读。
Composerize 可以用 npm 安装。确保你的系统中已经安装了 Nodejs。如果没有安装请按照下面的链接来安装 Nodejs。
* [如何在 Linux 上安装 NodeJS][2]
安装完 Nodejs 后,运行以下命令来安装 Composerize
```
$ npm install composerize
```
该命令将只为当前用户安装 Composerize。
如果你想在全局(全系统)安装它,请运行上述命令并加上 `-g` 选项,如下所示。
```
$ npm install composerize -g
```
### 用 Composerize 将 Docker 运行命令转换为 Docker-Compose 文件
要将 docker run 命令转换为 docker-compose 格式,只需用 Composerize 运行它,如下所示:
```
$ composerize docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer
```
它将以 docker compose 文件格式生成内容。
**示例输出:**
```
version: '3.3'
services:
portainer:
ports:
- '9000:9000'
volumes:
- '/var/run/docker.sock:/var/run/docker.sock'
image: portainer/portainer
```
![Convert Docker Run Commands Into Docker-Compose Files With Composerize][3]
现在在你的 `docker-compose.yml` 文件中复制上面几行。就这么简单!
正如我所说,你也可以使用 Composerize 网络服务将 docker run 命令转换成 docker 文件格式。
进入 **[https://www.composerize.com/][4]**,将 `docker run` 命令粘贴到框中,你就会立即得到 docker-compose 文件!
![Turn Docker Run Commands Into Docker-compose Files Using Composerize][5]
将命令转换为 docker-compose 文件后,到你保存 `docker-compose.yml` 文件的位置,运行以下命令来启动 Docker 应用:
```
$ docker-compose up
```
Composerize 是对 Docker 用户有用的工具之一。你现在可以安全地告别漫无边际的 Docker 命令了。
**资源:**
* [Composerize GitHub 仓库][6]
--------------------------------------------------------------------------------
via: https://ostechnix.com/convert-docker-run-commands-into-docker-compose-files/
作者:[sk][a]
选题:[lkxed][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://ostechnix.com/author/sk/
[b]: https://github.com/lkxed
[1]: https://ostechnix.com/introduction-to-docker-compose/
[2]: https://ostechnix.com/install-node-js-linux/
[3]: https://ostechnix.com/wp-content/uploads/2022/08/Convert-Docker-Run-Commands-Into-Docker-Compose-Files-With-Composerize.png
[4]: https://www.composerize.com/
[5]: https://ostechnix.com/wp-content/uploads/2022/08/Turn-Docker-Run-Commands-Into-Docker-compose-Files-Using-Composerize.png
[6]: https://github.com/magicmark/composerize