Dong Nguyen
Docker

Clear container logs

sudo sh -c "truncate -s 0 /var/lib/docker/containers/*/*-json.log"

View image content

docker run -it --entrypoint sh image_name

Run docker with limited mem/cpu

docker run --network host --restart unless-stopped --name gvms-hlgen-12 --cpus=".5" --memory="200m" -v /storage/data/greenvms:/tmp gvms-hlsgen-runtime --camera_id=12 --rtsp_url=rtsp://192.168.0.146:8551/stream --store_dir=/tmp/streams

Run docker container with host network

# try
docker run --network host ...

# or create network
docker network create -d bridge --subnet 192.168.0.0/24 --gateway 192.168.0.1 dockernet
# then
docker run --network dockernet ...

Run docker inside docker container

A container, with Docker installed, does not run its own Docker daemon, but connects to the Docker daemon of the host system. That means, you will have a Docker CLI in the container, as well as on the host system, but they both connect to one and the same Docker daemon. At any time, there is only one Docker daemon running in your machine, the one running on the host system.

To achieve this, you can start a Docker container, that has Docker installed, with the following bind mount option:

-v /var/run/docker.sock:/var/run/docker.sock

For example, you can use the docker image, which is a Docker image that has Docker installed, and start it like this:

docker run -ti -v /var/run/docker.sock:/var/run/docker.sock docker

And then inside the Docker container that you just started, run some Docker commands, for example:

docker images
docker ps

Observe the output. The output is exactly the same as when you run these commands on the host system.