I defined a command in compose.yml like command: “python manage.py runserver” it works fine. But when I built t

I think you are confused between docker-compose and docker. Think docker-compose as a helper utility that help you easily setup docker environment. When you do docker-compose up, it will create a new image and setup docker container for you with all the configuration that you have specified. Your application will run inside the docker container. Docker-compose just makes life little easier.

However, if you want to just use the docker command you need to specify the same port-mapping and other configurations in the dockerfile itself.

When you do docker run image it will create container for you. But you need to provide entrypoint or command to start your application otherwise it will just exit as docker does not know what to do next. In your case I suppose is a Django project and you need to specify "python manage.py runserver" to start your django server. In dockerfile you can specify it using CMD attribute:

CMD [ "python", "manage.py", "runserver" ]

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top