Docker Commands
Installation
sudo apt-get update
sudo apt-get -y install docker.io
--add-host="" : Add a line to /etc/hosts (host:IP)
# https://docs.docker.com/engine/install/ubuntu
sudo service docker start
sudo usermod -a -G docker ubuntu
sudo apt install docker-compose
Containers
List
docker image ls -all #show all images
docker container ls --all #show all containers
docker info #Display system-wide information
docker info --format '{{.LoggingDriver}}'
Lifecycle
- docker create creates a container but does not start it.
- docker rename allows the container to be renamed.
- docker run creates and starts a container in one operation.
--env, -e = Set environment variables
docker run <image_name>
# override entrypoint
docker run --rm -it --entrypoint /bin/bash cr0hn/festin
docker run --rm -it -p=8080:8080 inventree/inventree
- docker rm deletes a container.
- docker update updates a container's resource limit
Starting and Stopping
- docker start starts a container so it is running
- docker stop stops a running container
- docker restart stops and starts a container
- docker pause pauses a running container, "freezing" it in place
- docker unpause will unpause a running container
- docker wait blocks until running container stops
- docker kill sends a SIGKILL to a running container
- docker attach will connect to a running container
docker start **CONTAINER ID**
Info
- docker ps shows running containers.
Options:
-s (for getting docker ip)
- docker logs gets logs from container. (You can use a custom log driver, but logs is only available forjson-fileandjournaldin 1.10).
Options:
--details Show extra details provided to logs
-f, --follow Follow log output
--since string Show logs since timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)
--tail string Number of lines to show from the end of the logs (default "all")
-t, --timestamps Show timestamps
--until string Show logs before a timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)
Example
docker logs -t --since 2018-08-02T00:00:00 example-prod
docker logs --timestamps --since='2019-04-22T14:40:36.750121287Z' --until='2019-04-22T15:30:36.750121287Z' kafkaconsumer_kafka-smap-consumer.1.7uq0n8eysgxf5wnx0pbu4lwcx
docker logs smap-archiver > stdout.log 2>stderr.log
- docker inspect looks at all the info on a container (including IP address).
- docker events gets events from container.
- docker port
<container_name>
shows public facing port of container. - docker top shows running processes in container.
- docker top <container_name>
- docker stats shows containers' resource usage statistics.
- docker diff shows changed files in the container's FS.
- docker secret - Manage docker secrets
- create, inspect, ls, rm
Images
Images are just templates for docker containers.
https://hub.docker.com/r/ealen/echo-server
https://hub.docker.com/_/hello-world