[Fixed]-How to translate docker-compose.yml to Dockerfile

18đź‘Ť

âś…

TL;DR

You can pass some informations to your Dockefile (the command to run) but that wouldn’t be equivalent and you can’t do that with all the docker-compose.yml file content.

You can replace your docker-compose.yml file with commands lines though (as docker-compose is precisely to replace it).


In your case you can add the command to run to your Dockerfile as a default command (which isn’t roughly the same as passing it to containers you start at runtime) :

CMD ["python", "jk/manage.py", "runserver", "0.0.0.0:8081"]

or pass this command directly in command line like the volume and port which should give something like :

docker run -d -v .:/code -p 8081:8080 yourimage python jk/manage.py runserver 0.0.0.0:8081

BUT

Keep in mind that Dockerfiles and docker-compose serve two whole different purposes.

  • Dockerfile are meant for image building, to define the steps to build your images.

  • docker-compose is a tool to start and orchestrate containers to build your applications (you can add some informations like the build context path or the name for the images you’d need, but not the Dockerfile content itself).

So asking to “convert a docker-compose.yml file into a Dockerfile” isn’t really relevant.

That’s more about converting a docker-compose.yml file into one (or several) command line(s) to start containers by hand.

The purpose of docker-compose is precisely to get rid of these command lines to make things simpler (it automates it).

also :

From the manage.py documentation:

DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone
through security audits or performance tests. (And that’s how it’s
gonna stay.

Django’s runserver included in the manage.py tool isn’t meant for production.

You might want to consider using a WSGI server behind a proxy.

👤vmonteco

Leave a comment