✅ 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
Pobiega6mo ago
so what happens when you do docker compose up?
The Fog from Human Resources
it pulls the thing and starts it
The Fog from Human Resources
at least from what it looks like
Pobiega
Pobiega6mo 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 ..."
The Fog 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
The Fog from Human Resources
my only deployment experience was pulling everything to root and manually executing it :stare:
Pobiega
Pobiega6mo ago
so docker logs <container id>
The Fog from Human Resources
i only have images i dont know why there is no container
Pobiega
Pobiega6mo ago
No description
Pobiega
Pobiega6mo ago
docker-compose-your_service-1 is your container name here
The Fog 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
Pobiega6mo ago
wait what thats a database port
Pobiega
Pobiega6mo ago
why on earth would you set a HTTP server as a reverse proxy for a database?
The Fog from Human Resources
i want to bind 3306 to db.mydomain
Pobiega
Pobiega6mo ago
you should not expose your database publicly wtf
The Fog from Human Resources
isnt it public either way if its accessible from 3306
Pobiega
Pobiega6mo ago
only if you expose port 3306 to the internet but you dont do that.
The Fog from Human Resources
then what do i do cause my backend requires a server address
Pobiega
Pobiega6mo 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?
The Fog 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
Pobiega6mo ago
ok sure
Pobiega
Pobiega6mo ago
No description
Pobiega
Pobiega6mo ago
so like this?
Pobiega
Pobiega6mo ago
ok great
The Fog from Human Resources
:SCcrying:
Pobiega
Pobiega6mo 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"
The Fog from Human Resources
does my domain count
Pobiega
Pobiega6mo ago
no, as I would assume that points to your external IP address
The Fog 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
Pobiega6mo ago
yeah tahts fine
The Fog from Human Resources
i include this right?
Pobiega
Pobiega6mo 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?
The Fog from Human Resources
ye but its still crashing :SCgetoutofmyhead:
Pobiega
Pobiega6mo ago
start it without -d so we can see why
The Fog 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
Pobiega6mo ago
hm, can we go to voice/screenshare?
The Fog from Human Resources
i cant at the moment it must be getting passed properly
Pobiega
Pobiega6mo ago
likely can you show your new compose file?
The Fog 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
Pobiega6mo 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
The Fog 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
Pobiega6mo ago
yeah its enabled by default on docker desktop
The Fog from Human Resources
:SCcrying:
Pobiega
Pobiega6mo ago
hm is your database binding to localhost or 0.0.0.0?
The Fog from Human Resources
Uh Where can I check that
Pobiega
Pobiega6mo ago
sudo ss -tulpn | grep LISTEN
Keswiik
Keswiik6mo ago
Is there any reason your database isn't hosted in docker?
Pobiega
Pobiega6mo 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
The Fog from Human Resources
Not rly I just had it installed like that 127.0.0.1 and 0.0.0.0
Pobiega
Pobiega6mo ago
oh, so both?
Pobiega
Pobiega6mo ago
thats not what that means :p thats listening only on 127.0.0.1
The Fog from Human Resources
ah :SCWHATISGOINGON:
Pobiega
Pobiega6mo 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
The Fog from Human Resources
i need to set it to 3306 instead of the example 5432 right? it runs
Pobiega
Pobiega6mo ago
ya
The Fog from Human Resources
:plink:
Pobiega
Pobiega6mo ago
so it works now?
Pobiega
Pobiega6mo ago
yay
The Fog from Human Resources
but i have another question
Pobiega
Pobiega6mo ago
ye
The Fog 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
Pobiega6mo ago
you can do that with an env var
The Fog from Human Resources
is it that EXPOSE param in the dockerfile?
Pobiega
Pobiega6mo 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?
The Fog from Human Resources
i want it to use port 712 i thought this would bind the port ports: - "712:8080"
Pobiega
Pobiega6mo ago
correct
The Fog from Human Resources
so to the outside my app is running on :712? it seems to be
Pobiega
Pobiega6mo ago
yes
Pobiega
Pobiega6mo ago
left side is "docker host", right side is "inside container"
The Fog 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
Pobiega6mo 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
The Fog from Human Resources
i do have a question tho
Pobiega
Pobiega6mo 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 🙂
The Fog 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
Pobiega6mo 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
The Fog from Human Resources
ye its what i thought of when i saw how EF Core works
Pobiega
Pobiega6mo ago
Id say multiple contexts is the "standard" way, assuming there is no cross-concern
The Fog 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
Pobiega6mo 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
The Fog 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