AkatQuas / sprinkle-thoughts

[OBSOLETED] 读书笔记,阅读理解,原理学习,等等。转 blog 了。

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

docker command cheatsheet

AkatQuas opened this issue · comments

commented

On a Single Machine

  • build images from configuration file

    docker build -t <tag> -f <path/to/Dockerfile> .
  • files copying between host and containers

    docker cp host_source_path container:destination_path
    
    docker cp container:source_path host_destination_path
  • interactive with exisiting container

    docker exec -it <container> bash
  • run images interactively

    docker run -it <image>
  • remove container automatically when it exit

    # using --rm 
    docker run --rm <image>
  • clear exited containers

    docker rm $(docker ps -a -q -f status=exited)
    
    # in higher version
    docker container prune
  • give an port automatically to container

    docker run -d -P --name <GIVEN CONTAINER NAME> <image>

    In the above command, -d will detach our terminal, -P will publish all exposed ports to random ports and finally --name corresponds to a name we want to give. Now we can see the ports by running the docker port [CONTAINER] command.

  • specify a port to a container

    docker run -p <host port>:<container port> <webapp image>

On a Cluster/Compose

  • launch a composed application:

    docker-compose up -v -d

    -v means verbose, -d means detaching from terminal.

  • check the network running

    docker-compose ps
  • stop a composed application

    docker-compose down -v 

    This would kill all the containers and remove all data volumes if there any. Then we need to remove the network

    docker network rm <network-name>

    To list all the network we have now, use docker network ls.

  • inspect a network

    docker network inspect <network-name>

    This would print out the infomation in JSON format.