Following are some quick tips related to Docker and LXC/LXD containers:
To remove all unused docker images with no associated container enter the following command:
docker image prune --all
To get the console output of a Docker container, enter the following command:
docker logs [container-id]
To get the console output in real time use the -f switch
To run a Docker container in detached mode, use the -d switch. For example:
docker run -d [image-name]
The Docker restart policy determines how a Docker container should be restarted once it exits. The restart policy is specified using the —restart flag. The default value of this flag is “no”. To automatically start the container each time the Docker daemon starts, the restart flag should be set to “always”. For example:
docker run --restart="always" [image-name]
This can be used to automatically run Docker containers when the server boots.
To list LXC containers, the lxc-ls command should be used. It supports flags for listing running and stopped containers. For example to list all running LXC containers, use the following command:
lxc-ls --running