Docker base commands

List currently running containers

docker container ls

List all containers

docker container ls -a

Launch container on port 80 detached**

docker run --publish 80:80 --detach nginx

Launch container on port 80 detached

docker run --publish 80:80 --detach --name nginx_webserver nginx

Stop a container by name

docker container stop {CONTAINER_NAME OR ID}

Remove a container by name or by ID

(multiple names possible if separated by space)

docker container rm {CONTAINER_NAME OR ID}

Remove a running container by name or by ID

(this command stops the container and removes it)

docker container rm -f {CONTAINER_NAME OR ID}

Display container logs

docker container logs nginx_webserver

Display running process in docker conainer

docker container top {CONTAINER_NAME OR ID}

List useful informations in json format

docker container inspect {CONTAINER_NAME OR ID}

Display container usage info (cpu, ram, network…)

docker container stats {CONTAINER_NAME OR ID}

Launch bash inside a running container to exec commands

docker container exec -it {CONTAINER_NAME OR ID} bash

For other infos, check “docker inspect” command json path

docker container inspect --format "{{.NetworkSettings.IPAddress}}"  
{CONTAINER_NAME OR ID}
Next