Easily turn docker run commands into docker-compose files
In this blog post I will cover about few libraries and websites which converts the docker run commands into docker-compose files.
composerize
composerize can be used from cli and website.
Using from CLI
composerize is available as npm package.
install the composerize with following command.
npm install composerize -g
Code language: plaintext (plaintext)
After installing you can use it like below to produce equivalent docker-compose instructions.
composerize docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=admin mysql:5.7
Code language: plaintext (plaintext)
The above command prints the out on command line
![](https://fullstackcode.dev/wp-content/uploads/2022/07/2022-07-21-01_03_30-Greenshot-1024x240.webp)
Instead of copying from console If you are using powershell you can redirect output to file using below command
composerize docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=admin mysql:5.7 > docker-compose.yml
Code language: plaintext (plaintext)
Using from website
instead of installing the library you can also use directly from website https://www.composerize.com/
![](https://fullstackcode.dev/wp-content/uploads/2022/07/2022-07-21-01_01_39-Composerize-Brave-1024x638.webp)
Note
I observed that using detached flag in certain places generate wrong docker-compose file
Eg : docker run –name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:5.7
above command is a valid docker command but composerize generates wrong docker-compose file.
place your detach flag just after run to generate proper file.
docker run -d –name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw mysql:5.7
docker-compose Converter Web
docker-compose Converter Web ( dcc-web) is another website (https://bucherfa.github.io/dcc-web/) converts docker run commands to docker-compose.yml files.
![](https://fullstackcode.dev/wp-content/uploads/2022/07/2022-07-30-18_26_56-Greenshot-1024x582.webp)