✅ Need help with docker deployment

I have an ASP.NET REST API that i want to deploy on my server but i dont understand how this works at all My image is already pushed but when i try to access my API via CURL request nothing happens Im using docker-compose on my server
version: '3'

services:
your_service:
image: ...
environment:
...
ports:
- "712:8080"
version: '3'

services:
your_service:
image: ...
environment:
...
ports:
- "712:8080"
87 Replies
Pobiega
Pobiega4w ago
so what happens when you do docker compose up?
Somgör from Human Resources
it pulls the thing and starts it
Somgör from Human Resources
at least from what it looks like
Pobiega
Pobiega4w ago
yep, seems fine and the image itself, you are sure it listens on the correct ports? you should be able to look in the logs of the container and see the ASP.NET logging output, like "listening on ..."
Somgör from Human Resources
i just dont know what im missing, im also trying to bind 3306 to a db. subdomain but nothing works on there either my connection requests time out how can i access the logs
Somgör from Human Resources
my only deployment experience was pulling everything to root and manually executing it :stare:
Pobiega
Pobiega4w ago
so docker logs <container id>
Somgör from Human Resources
i only have images i dont know why there is no container
Pobiega
Pobiega4w ago
No description
Pobiega
Pobiega4w ago
docker-compose-your_service-1 is your container name here
Somgör from Human Resources
the thing crashes cause i cant connect to the db i set a reverse proxy using NGINX on port 3306 idk whats up with that
Pobiega
Pobiega4w ago
wait what thats a database port
Pobiega
Pobiega4w ago
why on earth would you set a HTTP server as a reverse proxy for a database?
Somgör from Human Resources
i want to bind 3306 to db.mydomain
Pobiega
Pobiega4w ago
you should not expose your database publicly wtf
Somgör from Human Resources
isnt it public either way if its accessible from 3306
Pobiega
Pobiega4w ago
only if you expose port 3306 to the internet but you dont do that.
Somgör from Human Resources
then what do i do cause my backend requires a server address
Pobiega
Pobiega4w ago
slow down a sec is this database only for the containerized app, or is it something you want on the host-server itself, ie, available for all apps on that server?
Somgör from Human Resources
the database runs on the actual server which allows me to use it for all applications on that server its just a few so i just give every program its own database
Pobiega
Pobiega4w ago
ok sure
Pobiega
Pobiega4w ago
No description
Pobiega
Pobiega4w ago
so like this?
Pobiega
Pobiega4w ago
ok great
Somgör from Human Resources
:SCcrying:
Pobiega
Pobiega4w ago
ok so to access the host machine from inside the container, you can either use the internal IP address of the server, or set up an extra_hosts directive in your compose file
extra_hosts:
- "host.docker.internal:host-gateway"
extra_hosts:
- "host.docker.internal:host-gateway"
Somgör from Human Resources
does my domain count
Pobiega
Pobiega4w ago
no, as I would assume that points to your external IP address
Somgör from Human Resources
the thing is that the DB host is passed as env variable by the docker-compose file which is then read by the backend
Pobiega
Pobiega4w ago
yeah tahts fine
Somgör from Human Resources
i include this right?
Pobiega
Pobiega4w ago
put that in your compose file, yes and then change the "DB host" env var to be host.docker.internal and your db is listening on 3306 locally, right?
Somgör from Human Resources
ye but its still crashing :SCgetoutofmyhead:
Pobiega
Pobiega4w ago
start it without -d so we can see why
Somgör from Human Resources
i can see the error it cant connect to the specified mysql host can i see the env variables with some command maybe something isnt getting passed properly
Pobiega
Pobiega4w ago
hm, can we go to voice/screenshare?
Somgör from Human Resources
i cant at the moment it must be getting passed properly
Pobiega
Pobiega4w ago
likely can you show your new compose file?
Somgör from Human Resources
version: '3'

services:
gitlink:
image: image
environment:
DB_SERVER: host.docker.internal
DB_USER: DB_user
DB_PASSWORD: DB_user_password
GITTHUB_TOKEN: gh_token
ports:
- "712:8080"
extra_hosts:
- "host.docker.internal:host-gateway"
version: '3'

services:
gitlink:
image: image
environment:
DB_SERVER: host.docker.internal
DB_USER: DB_user
DB_PASSWORD: DB_user_password
GITTHUB_TOKEN: gh_token
ports:
- "712:8080"
extra_hosts:
- "host.docker.internal:host-gateway"
Pobiega
Pobiega4w ago
ok, looks fine at a glance ok lets try this replace host-gateway with 172.17.0.1 thats the hosts internal IP inside dockers network actually, some people are saying you should be able to use the hosts hostname
Somgör from Human Resources
still cant connect i used host.docker.internal on my debugging .env file too and it worked on my PC i have XAMPP for mysql and on WSL i have mariaDB which the backend was both able ot connect to
Pobiega
Pobiega4w ago
yeah its enabled by default on docker desktop
Somgör from Human Resources
:SCcrying:
Pobiega
Pobiega4w ago
hm is your database binding to localhost or 0.0.0.0?
Somgör from Human Resources
Uh Where can I check that
Pobiega
Pobiega4w ago
sudo ss -tulpn | grep LISTEN
Keswiik
Keswiik4w ago
Is there any reason your database isn't hosted in docker?
Pobiega
Pobiega4w ago
alternatively sudo lsof -nP -iTCP -sTCP:LISTEN since im pretty sure mysql uses TCP actually, might as well target the port since its a known one: sudo lsof -nP -i:3306 cause if its not binding to 0.0.0.0, we will have to add a relay and honestly, since its on the host, it would probably be a bad idea to bind to 0.0.0.0 anyways depends on how the server is exposed to the internet
Somgör from Human Resources
Not rly I just had it installed like that 127.0.0.1 and 0.0.0.0
Pobiega
Pobiega4w ago
oh, so both?
Pobiega
Pobiega4w ago
thats not what that means :p thats listening only on 127.0.0.1
Somgör from Human Resources
ah :SCWHATISGOINGON:
Pobiega
Pobiega4w ago
https://dev.to/mjnaderi/accessing-host-services-from-docker-containers-1a97 check this blogpost, scroll down to "solution using socat" that should do the trick for you
Somgör from Human Resources
i need to set it to 3306 instead of the example 5432 right? it runs
Pobiega
Pobiega4w ago
ya
Pobiega
Pobiega4w ago
so it works now?
Pobiega
Pobiega4w ago
yay
Somgör from Human Resources
but i have another question
Pobiega
Pobiega4w ago
ye
Somgör from Human Resources
how can i change the port of my ASP.NET backend? 8080 is in use for a temp backend i cant dispose atm
Pobiega
Pobiega4w ago
you can do that with an env var
Somgör from Human Resources
is it that EXPOSE param in the dockerfile?
Pobiega
Pobiega4w ago
no, that tells docker to expose that port on the container so you must change that too, ofc, to match whatever port your backend wants to use but uh you do know that whatever port is used inside the container dont need to match the outside, right?
Somgör from Human Resources
i want it to use port 712 i thought this would bind the port ports: - "712:8080"
Pobiega
Pobiega4w ago
correct
Somgör from Human Resources
so to the outside my app is running on :712? it seems to be
Pobiega
Pobiega4w ago
yes
Pobiega
Pobiega4w ago
left side is "docker host", right side is "inside container"
Somgör from Human Resources
i got 401 on my test script which is the expected result yeees it works also ive been getting into EF Core insead of writing SQL queries i love it :stare:
Pobiega
Pobiega4w ago
yeah its good. very convention-based, and if your app needs to run a lot of very complicated queries it might become hard thou
Somgör from Human Resources
i do have a question tho
Pobiega
Pobiega4w ago
I'd recommend using EF for most code, and use the raw underlying connection if you ever need to make a 4-way join or something 🙂
Somgör from Human Resources
my bigger projects dont always involve only one database for example id have a database for things like settings and another one for user accounts for this id be able to not select a db on my connection string and just go SELECT * FROM Settings.local_settings; for example, on EF Core i did that by making a DBContext Factory that takes a database as input and sets it, is that how it works?
Pobiega
Pobiega4w ago
there are many ways to do it one would be to have more than one context you could have a UserDataDbContext and a SettingsDbContext for example
Somgör from Human Resources
ye its what i thought of when i saw how EF Core works
Pobiega
Pobiega4w ago
Id say multiple contexts is the "standard" way, assuming there is no cross-concern
Somgör from Human Resources
i just didnt have the chance to test it yet cause my current project (first with EF Core) only involves a single DB btw when i push a new image to docker and run that docker compose command, itt will update and deploy the image right?
Pobiega
Pobiega4w ago
I think so yeah. if you dont specify an image version, it assumes latest oh and btw, I would recommend moving away from mysql if I were you its not a very good database engine. postgres is just superior in every way these days
Somgör from Human Resources
originally i didnt like the way PSQL worked but i dont think with EF core thats an issue anymore
Want results from more Discord servers?
Add your server
More Posts