Datadog agent + app stages in same dockerfile
Hi ! Following @Rafal 's suggestion in thread #Recommended way of connecting datadog-agent
I tried running a datadog agent and an app in the same Dockerfile (two stages since we have FROM datadog/agent:7 for the agent and FROM node:16.6.1-alpine3.14 for the app).
Locally it works perfectly fine, both stages are working. But on railway, only the second one is ran : the app one. The datadog agent stage is discarded, any idea why ?
Here is the dockerfile :
Solution:Jump to solution
try this again but use
service datadog-agent start
instead of the systemctl thing56 Replies
Project ID:
6bd9c9dd-822c-457b-a37e-0abf3c4579fb
6bd9c9dd-822c-457b-a37e-0abf3c4579fb
Doesnt using
FROM
start a fresh layer without anything from the one before? π€
From the docker docs.
With multi-stage builds, you use multiple FROM statements in your Dockerfile. Each FROM instruction can use a different base, and each of them begins a new stage of the build. You can selectively copy artifacts from one stage to another, leaving behind everything you donβt want in the final image. To show how this works, you can adapt the Dockerfile from the previous section to use multi-stage builds.
Yes I think so, and that's not a problem.
I tried this locally and it worked with this exact dockerfile. But it seems like on railway the first stage is simply not launched, whereas locally it is.
Are you sure on that? Ive never seen a dockerfile act the way you're describing.
I think you're right, I might have misunderstood the problem
im with luna on this, anything that you install or launch in the previous FROM derivative is not carried over to the next FROM unless you explicitly copy it over
Ok good thing we got that out of the way, thank you.
I removed the app's stage and only kept the datadog one here is the docker file :
The agent is running fine but I don't see any activity of the container in my datadog dashboard, why is that ?
When running this exact one locally I see the container on my dashboard.
When running it locally are you passing in the docker socket by chance?
What do you mean ?
Whatre you actually trying todo? I have a feeling you may not need the agent at all for this.
So I have this app :
And the docker agent container running on my computer.
This lets me monitor the app.
Now I'm only trying to run the container on railway without the app to see if I see it on the datadog dashboard
I see
Just like I see it when i simply run the container locally
Okay so you will need the agent just inside the container with your node app.
Or π€
https://railway.app/template/78cMS9
theoretically this is what I want
The thing is before doing that, I'm trying to understand why does the container running right now on railway isn't detected by my dashboard
I have an idea, is it possible to edit the
docker run
command used to run the container on railway ?no
You might need to use their alpine container and then install node on that.
or install the agent in the node image with data dog's install script
Local
Railway
I see some differences in the logs
do you have any idea why that's happening ?
Could you give me more details about how to do that ?
UNTESTED
think of this as a pseudo dockerfile
GitHub
GitHub - gdraheim/docker-systemctl-replacement: docker systemctl re...
docker systemctl replacement - allows to deploy to systemd-controlled containers without starting an actual systemd daemon (e.g. centos7, ubuntu16) - GitHub - gdraheim/docker-systemctl-replacement...
π€·
That's clever let me try that
thanks
it likely wont work
due to that ?
I don't know what that link is complaining about
have you set your
DD_API_KEY
in the service variablesYes I did
"/bin/sh: 1: systemctl: not found" :/
well luna did warn us lol
and i did say it would likely not work
I'mma try her approach
So the app runs :
Example app listening on port 3000!
But the agent doesn't (at least I don't have anything on the DD dashboard).
i'm in local
is there a way to see the logs of the agent ?
here is the dockerfile
what do the deployment logs look like
the railway deployment logs
I didn't deploy on railway
Let me deploy that config
where did you deploy it
that's local
the container on my pc
well get to deploying lol
Not surprising
doesn't look like the agent was started
Solution
try this again but use
service datadog-agent start
instead of the systemctl thing+ it worked locally
is it working because you used
service datadog-agent start
Yes I think so
Thanks for that
+ it simplifies the dockerfile
what web framework are you using
express js
read this please
https://docs.railway.app/troubleshoot/fixing-common-errors
It works !
does datadog work too?
i know the agent starts, but do logs show in the datadog site
Yes i have the logs too
Thanks a lot @Brody @ImLunaHey
no problem!