Question

deploy a docker image in general and with django

I struggle to grasp how to expose a docker image that exists in DO droplet or a registry.

Precisely, I’m looking at how to connect the doecker-compose image to the droplet/application.

I created a docker droplet, installed docker-compose on it (ubunto 20.04).

From docker-hub and/or github I then pushed the image to the droplet

Separately, I also push it to the registry.

on Doctl I then run docker-compose --build

and then: docker-compose up -d

I can observe that the image exists was build on the droplet, or pushed to the registry. But then, what happens next? How I can display the up image on my droplet or my application?

I wish to avoid cubernetics to tackle my problem, as it adds another layer of complexity.

Any input would be highly appreciated.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
April 27, 2023

Hi there,

It sounds like you have successfully deployed your Docker image using docker-compose. To expose the application running inside the Docker container to the outside world you have to map the container port to the host (Droplet) port:

  1. First, update your docker-compose.yml file to include the ports section. For example, if your Django application is running on port 8000 inside the container, you can map it to port 8000 on the Droplet:
version: '3'

services:
  your_service_name:
    image: your_image_name
    ports:
      - "8000:8000"

Replace your_service_name and your_image_name with your actual service and image names.

  1. Run docker-compose down to stop the currently running containers and services.

  2. Run docker-compose up -d again to restart the containers with the new port configuration.

  3. Ensure that your Django application is configured to allow connections from any IP. In your Django project settings, update the ALLOWED_HOSTS setting:

ALLOWED_HOSTS = ['*']

Note: This configuration is insecure for production environments. Use specific domain names or IP addresses instead of the wildcard * in production.

  1. Now your application should be accessible through your Droplet’s IP address on port 8000: http://DROPLET_IP_ADDRESS:8000

For better security and user experience, you can configure a reverse proxy (such as Nginx) to serve your application on port 80 (HTTP) or 443 (HTTPS). Additionally, you can set up a domain name to point to your Droplet’s IP address.

Feel free to share your docker-compose.yml file and I will be happy to advise you on what changes you need to make!

An alternative option is to deploy your Django app on the DigitalOcean App Platform so that you would get automated builds and deployments whenever you push your changes to your Git repository and will not have to do any server management:

https://docs.digitalocean.com/tutorials/app-deploy-django-app/

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up