Running a ubuntu container in background using docker compose
This is normal.
You are starting an ubuntu container with bash
as the command (thus the root process). The thing is to keep bash alive you need to attach it with a terminal. This is why when you want to get a bash in a container, you're using -ti
with your command :
docker container exec -ti [my_container_id] bash
So if you want to keep your ubuntu container alive and don't want to attach it to a terminal, you'll have to use a process that will stay alive for as long as you want.
Below is an example with sleep infinity
as your main process
version: "3"services: ubuntu: container_name: ubuntu image: ubuntu restart: on-failure command: ["sleep","infinity"]
With this example, you container will stay running indefinitely.