By Lea Cards
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.
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!
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:
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.
Run docker-compose down to stop the currently running containers and services.
Run docker-compose up -d again to restart the containers with the new port configuration.
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.
http://DROPLET_IP_ADDRESS:8000For 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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.