Home Docker Convert Docker Run Commands Into Docker-Compose Files

Convert Docker Run Commands Into Docker-Compose Files

Create Docker compose files from docker run commands using Composerize

By sk
11.5K views

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 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 the command 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.

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
Convert Docker Run Commands Into Docker-Compose Files With Composerize

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/ 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
Turn Docker Run Commands Into Docker-compose Files Using Composerize

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:

You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More