1/3/2016 - 8:24 PM

Docker commands

Docker commands

## Usefull commands
# remove all images tagged <none>
docker rmi $(docker images | grep "^<none>" | awk "{print $3}")

# remove all stopped containers
docker rm $(docker ps -a -q)

# Executes the script from
sudo wget -qO- | sh

# version
docker version

# adds the current user to the docker group
sudo usermod -aG docker rod

# downloads an image for the linux busybox
docker pull busybox

# shows installed images
docker images

# run a docker image
docker run busybox echo "Hello World!"

# downloads all variants for an image
docker pull -a busybox

# run a docker container specifying the tag
docker run busybox:ubuntu-14.04

# downloads a image specifying tag
sudo docker pull busybox:ubuntu-14.04

# pulls an image from a private respository
sudo coker pull

# search for an image
docker search mysql

# launch a docker image
docker run -i -t ubuntu:14.04 /bin/bash

# detaches from the docker image

#lists runnin images
docker ps

# reatach to a container
docker attach cranky_pasteur

# show changes on a docker container
docker diff ed2e9f8eeabd

# stop a container
docker stop e584916bdea7

# list state of all containers
docker ps -a

# starts a stopped container
docker start e584916bdea7

# starts and attaches to a container
docker start -a e584916bdea7

# pause and unpause a container
docker pause 87627520c875
docker unpause 87627520c875

# run a container and automatically removes it
docker run -i - t --rm ubuntu:14.04 /bin/bash

# remove all containers that are not running
docker rm `docker ps -aq --no-trunc`

# commit a container with a tag
docker commit fe65ed21920c name:tag

# runs a container as a daemon
docker run -d 4e6b2f5bc542

# tag a docker image
docker tag 5eb3bd9e5fbf name:tag

# inspect a container
docker inspect e48468aa3b60

# inspect a container filtering information
docker inspect --format='{{.NetworkSettings.IPAddress}}' e48468aa3b60

# bind a host port to a container port HOST:CONTAINER
docker run -p 80:80 e48468aa3b60

# get the port on the host for a port in the container
docker port e48468aa3b60 80

# specify an ip address and port IP:HOST-PORT:CONTAINER-PORT
docker run -d -p

# auto bind a host port number to avoid conflicts
docker run -d -p 80 7f4c7901e952

# auto bind a host port number using a valid IP range
docker run -d -p 7f4c7901e952

# create bindings from exposed port on the image
docker run -d -P

# mount a volume in the container
docker run -v /home/rod/smart 7f4c7901e952

# assign folder in the host to a container
docker run -v /home/docker:/home/docker 32db8a2f4847

# lauch a data only container
docker run --name datavol -v /datamount busybox:latest /bin/true

# mount a volume from a data container
docker run -d -p 80:80 --volumes-from data_vol

# link two containters
docker run -d --link 32db8a2f4847:linked busybox:latest