Run a redis container in detached mode:
docker run -d redis
Run redis-cli on it:
docker exec -it e0c061a5700bfa400f8f24b redis-cli
where e0c061a5700bfa400f8f24b is the id of the container.
According to the documentation:
Detached (-d)
To start a container in detached mode, you use -d=true or just -d option. By design, containers started in detached mode exit when the root process used to run the container exits, unless you also specify the –rm option. If you use -d with –rm, the container is removed when it exits or when the daemon exits, whichever happens first.
.
–interactive , -i Keep STDIN open even if not attached
–tty , -t Allocate a pseudo-TTY