docker run <image_name>
e.g. docker run nginx
docker run = docker create + docker start
docker ps
To include all containers (including stopped ones) run: docker ps #####a
docker stop <container_name>
docker rm <container_name>
docker rmi <image_name>
docker pull <image_name>
docker exec #####it <container_name> <command>
e.g. docker exec my_container cat /etc/hosts
docker run #####d <container_name>
docker attach <container_name>
docker attach <first_4_digits_container_id>
docker images
docker run <image_name>:<image_version>
e.g. docker run redis:4.0
docker run -it <container_name>
-t
terminal
-i
interactive
docker run -p <docker_host_port>:<docker_container_port> <container_name> e.g.
docker run -p 80:5000 <container_name>`
docker run -v <external_dir>:<container_dir>
e.g. docker run -v /opt/datadir:/var/lib/mysql mysql
docker inspect <container_name>
docker logs <container_name>
docker build . #####t <username>/<image_name>
docker build #####t <your_docker_id>/<project_repo>:<image_version>
docker push <image_name>
docker login
docker login private-registry.io
docker run -e <env_variable_key=env_variable_value> <image_name>
docker run --entrypoint <new_entrypoint_vlaue> <image_name> <other_values>
docker run -d --name=<host_name> --link <container2_name>:<host2_name> <container_name>
e.g. docker run -d --name=vote --link redis:redis voting#####app
Note: links are not needed starting from version 2 of docker-compose file
docker run --cpus=.5 ubuntu
This will ensure that the container will not take more than 50% of the host CPU at any given time
docker run --memory=100m ubuntu
This will ensure that the container will not take more than 100m of the host memory at any given time
docker volume create <volume_name>
docker run -v <volume_name>:<volume_path> <container_name>
Note: this operation mounts a volume from the volumes directory Note: even if the container is destroyed, the data will remain valid.
docker volume ls
docker run -v <full_path_of_external_dir>:<volume_path> <container_name>
docker run --mount type=bind, source=<full_path_of_external_dir>, target=<volume_path> <container_name>
Note: mount any directory from the docker host
docker history <image_name>
docker system df
docker system df -v
docker network create ##########driver bridge ##########subnet <ip_address> <network_name>
docker network ls
docker inspect <cotainer_name_id>
docker exec -it <container_id> <command_prompt>
docker run --log-opt max-size=10m --log-opt max-file=5 my-app:latest
This sets a maximum of five log files with a max size of 10 Mb each. So at most 50 Mb of logs for that container.
docker stats <container_id>
docker cp <container_id>:/path/to/useful/file/local-path
docker run --restart <argument>
no
This is the default value, it means that the containers would not be restarted
on-failure
This would restart the container in case that there is an error and the container crashes
always
Always restart the container if it stops
unless-stopped
The container would always be restarted unless it was manually stopped
docker system df
docker rmi $(docker images | grep none | awk '{print $3}')
docker image inspect --format IMAGE <IMG_NAME>
docker image inspect -f IMAGE <IMG_NAME>