Docker Tips

Updated . Posted . Visible to the public.

Here you can learn about the docker basic and its commands

  1. How to execute the docker run command

The docker run command is used to get the specific docker image from registry and start and run the container of the image.
For this example, the alpine docker image is used as it is more light weight linux image.

docker run alpine:3.4 uptime

Here the apline is a public image and it will be pulled from registry and created the container and started the container and ran the 'uptime' and exit.

To log into container, run following command.

docker run -it alpine:3.4 sh

To keep the container in running state in detach mode, execute continuously running command.
For example

docker run -d alpine:3.4 ping www.google.com

To check the last ran container status.

docker ps -l

To see all the containers.

docker ps -a

To see only the last two containers.

docker ps -n 2
  1. How to start, stop and remove the containers

Container can be started using following command with container id or name.

docker start <container_id / container_name>

Container can be stopped using following command with container id or name.

docker stop <container_id / container_name>

Container can be removed using following command with container id or name.

docker rm <container_id / container_name>
  1. How to check the docker logs

docker logs <container_id / container_name>
  1. How to check the available docker networks

docker network ls
  1. How to log into running container

docker exec -it <container_id / container_name> /bin/bash
  1. How to build a image from Dockerfile

docker build -t <image name and version> . 
  1. How to list all the docker images

docker images

  1. How to remove a docker image


docker rmi <image id>
  1. How to inspect a container

You can find all the detail about the container
eg ip

docker inspect <container id> 

  1. If you want to get only the ip detail use following command
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container id> 

vasan
Last edit
vasan
Posted by vasan to vasan's deck (2016-11-30 08:15)