1 | initial version |
To run Nginx in the background and sleep in the foreground within a Docker container, you can follow these steps:
FROM nginx:latest
CMD nginx -g "daemon off;"
ENTRYPOINT sleep infinity
docker build -t mynginx .
docker run -d mynginx
This command will start the container in detached mode, meaning it will run in the background.
docker exec -it <container_name> /bin/bash
This will open a bash shell inside the container. From here, you can run the sleep
command to sleep in the foreground.
sleep 30
This command will sleep for 30 seconds before returning control to the terminal.
docker stop <container_name>