docker quick ref

Docker reference commands

  • Install a OS container
    • docker pull ubuntu
    • docker run -i -t ubuntu /bin/bash
  • Stop & delete
    • docker stop $(docker ps -a -q)
    • docker rm $(docker ps -a -q)
  • List docker running containers
    • docker ps 
  • List all docker containers
    • docker ps -a
  • Remove all docker images
    • docker rmi $(docker images -q)
  • Connecting to running container 
    • docker exec -it [container-id] bash
  • Controlling containers
    # Start a new container
  • $ JOB=$(sudo docker run -d ubuntu /bin/sh -c “while true; do echo Hello world; sleep 1; done”)
  • # Stop the container
  • $ sudo docker stop $JOB
  • # Start the container
  • $ sudo docker start $JOB
  • # Restart the container
  • $ sudo docker restart $JOB
  • # SIGKILL a container
  • $ sudo docker kill $JOB
  • # Remove a container
  • $ sudo docker stop $JOB # Container must be stopped to remove it 

  • $ sudo docker rm $JOB
  • Committing (saving) a container state
    Save your containers state to an image, so the state can be re-used.
    When you commit your container only the differences between the image the container was created from and the current state of the container will be stored (as a diff). See which images you already have using the
    docker images command.
    # Commit your container to a new named image
  • $ sudo docker commit <container_id> <some_name>
  • # List your containers
  • $ sudo docker images
    You now have an image state from which you can create new instances.
  • An Interactive Container
    Let’s try the docker run command again, this time specifying a new command to run in our container.
    $ sudo docker run -t -i ubuntu:14.04 /bin/bash
  •