Auto run a command inside docker after it starts


I’ve been trying to setup a can data receiver inside a container.
For the application to work, I need to set up the can device.
the command used for it is
“ip link set up can0 type can bitrate 5000”
it works fine when i run the command via interactive terminal mode.

but i want it to auto run on docker start. So, I added it to the docker file via
CMD [“ip link set up can0 type can bitrate 5000”]
but it doesn’t run. Still i need to do this manually.

Is there any idea as to why it is not working or do you have any suggestion on what I should do.



CMD is relative to the ENTRYPOINT script/command, fx. if the entrypoint script is / then it would be:

/ ip link set up can0 type can bitrate 5000

Which would properly not work.

So you need to check your image, what the entrypoint is, and if its a script, then you properly need to create your own entrypoint script / edit the current one to execute your command also.

If you need more help then we need to know which image you’re using :slight_smile:

1 Like

Thank you so much.

It was of great help. I was able to solve the problem.

As you mentioned I created a new script and it solved the issue.