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!
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.
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 theports
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:Replace
your_service_name
andyour_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: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: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