Running the container in detached mode
Okay, that was great, but what if we don't want to lock the Terminal from where we started the container? In most cases, it is inconvenient to have a Terminal session locked for each running container. It's time to learn how to start the container as detached – running the container without locking the Terminal!We can do this by adding the -d
option and, at the same time, giving it a name using the --name
option. Giving it a name is optional, and Docker will generate a name if we don't, but it makes it easier to send commands to the detached container using a name that we have decided. The --rm
option is no longer required since we will stop and remove the container explicitly when we are done with it:
docker run -d -p8080:8080 -e "SPRING_PROFILES_ACTIVE=docker" --name my-prd-srv product-service
If we run the docker ps
command again, we will see our new container, called my-prd-srv
:
