Run Specific commands when Container Start

Hello Masters!!

Please help me solve this problem.

I am running Caddy Webserver on Alpine Docker with Ubuntu 20.04 Host.

I need the Caddy Webserver to be run on specific directory when I run / re-create the container (home folder).

Right now, I need to login into the container and run the command manually.

The problem is when docker crash, it will auto restart the container but Caddy Webserver remain inactive.

I have tried to experiment with entrypoint and CMD but I don’t understand.

This is for personal hobby not for commercial activities.

Hopefully someone can help me.


Hi :slight_smile:

Which image are you using? And please describe what you have tried allready with entrypoint and cmd.

Just a quick FYI, normally entrypoint & cmd can be understood as:
entrypoint = the program you want to run
cmd = the arguments for that program

there are also many images that uses entrypoint=bash and something like cmd=/my/bash/

hope that helps a bit.


Glad to found your answer.

I am using Alpine:latest image.

As for entrypoint, I tried to use :

/bin/sh /
Workding dir set to :

but it says not found.

My script :

RUN apk update && upgrade
RUN cd /home/
RUN caddy start
RUN ping my.server.tld

What am I missing here?

Hi again

Whats in your if you want to run caddy?


I hope I don’t give wrong answer. is the one I posted above.

RUN apk update && upgrade
RUN cd /home/
RUN caddy start
RUN ping my.server.tld

Am I doing the right steps to make some commands be executed at container start?

If you want to use Docker with shell scripts, you need to learn at least two things. Docker and shell scripts :slight_smile: “RUN” is an instruction in Dockerfile. It won’t work in a shell script. Remove “RUN” from the beginning of every line and that should work if “caddy start” runs caddy in the background. Otherwise caddy would start and ping would never run until caddy stops…