How to Create Docker Container That Just Runs (forever) | Docker image

Docker Apr 5, 2022

This one is great for testing and debugging in case you're not sure which "docker-entrypoint" command you will be using in the end.

Lets's create simple Dockerfile:

# U can use whatever image
FROM alpine

RUN apk add nano

COPY docker-entrypoint.sh /

RUN ["chmod", "+x", "/docker-entrypoint.sh"]

CMD ["sh","-c","/docker-entrypoint.sh" ]

In the same folder lets create docker-entrypoint.sh (or call it however you want as long as it matches CMD - command above in Dockerfile):

#!/bin/bash


# Run if there is nothing to do :)
while true; do sleep 9999; done
docker build -t just_run . 

For quick test you could run one-liner like this:

docker run -d --name your-container-name just_run

Or you could put it in a docker-compose.yml ...

Tags

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.