Skip to content

Instantly share code, notes, and snippets.

@lifeofreilly
Last active September 22, 2015 02:20
Show Gist options
  • Save lifeofreilly/653d08bb0d3417f93b40 to your computer and use it in GitHub Desktop.
Save lifeofreilly/653d08bb0d3417f93b40 to your computer and use it in GitHub Desktop.
Docker Commands

Check that you have a working install

$ docker info
$ docker run hello-world

Download an ubuntu image

$ docker pull ubuntu

Reset Docker Virtual machine

$ docker-machine restart default # Restart the environment $ eval $(docker-machine env default) # Refresh your environment settings

Run an interactive shell in the Ubuntu image

$ docker run -i -t ubuntu /bin/bash

detach the tty without exiting the shell

$ Ctrl-p + q

To re-attach

$ docker exec -it [container-id] bash

Start a long running process

Start process

$ JOB=$(docker run -d ubuntu /bin/sh -c "while true; do echo Hello world; sleep 1; done")

Collect the output of the job so far

$ docker logs $JOB

Kill the job

$ docker kill $JOB

Listing containers

$ docker ps # Lists only running containers
$ docker ps -a # Lists all containers

Controlling containers

Start a new container

$ JOB=$(docker run -d ubuntu /bin/sh -c "while true; do echo Hello world; sleep 1; done")

Stop the container

$ docker stop $JOB

Start the container

$ docker start $JOB

Restart the container

$ docker restart $JOB

SIGKILL a container

$ docker kill $JOB

Remove a container

$ docker stop $JOB # Container must be stopped to remove it
$ docker rm $JOB

Commiting changes to a container

$ docker commit [container] [some_name] # Commit your container to a new named image

List your images

$ docker images

Remove image

$ docker rmi [id]

Build a new image

$ docker build -t keywizard .

Map ports to locahost

$ docker run -d -p 0.0.0.0:9080:9080 -p 0.0.0.0:9081:9081 keywizard
VirtualBox > Settings > Network > Port Forwarding > New > (TCP | Host Port | Guest Port)

Inspect running image

$ docker inspect [image]

Tail logs of a running image

$ docker logs -f [image]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment