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.
Code language: plaintext (plaintext)npm install composerize -g
After installing you can use it like below to produce equivalent docker-compose instructions.
Code language: plaintext (plaintext)composerize docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=admin mysql:5.7
The above command prints the out on command line

Instead of copying from console If you are using powershell you can redirect output to file using below command
Code language: plaintext (plaintext)composerize docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=admin mysql:5.7 > docker-compose.yml
Using from website
instead of installing the library you can also use directly from website https://www.composerize.com/

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.
