docker cheat sheet

images

# Pull an image
docker pull [image-name]

# List all images
docker images

# Remove image
docker rmi [image-id]

# Build image from Dockerfile
docker build [path]

# Build image from Dockerfile with name:tag
docker build -t [name]:[tag] [path]

# Save image as file (tar archive)
docker save -o [path-for-file] [image-name]

# Load image from file (tar archive)
docker load -i [path-to-file]

container

# List running containers 
docker ps

# List all containers
docker ps -a

# Create container
docker create [options] [image-name] [command]
# Common options are:
# -v     to mount volume, i.e.: -v /some/path/on/host/:/path/in/container
# -p     to map ports from host to container, i.e.: -p 50080:80
# -it    to run container interactivly
# -d     to run container detached
# --name to give the container a name, i.e.: --name johndoe

# Start container
docker start [container-id or name]

# Start container attached
docker start -a [container-id or name]

# Create and run container, for options see docker create command
docker run [options] [image-name] [command]

# Stop container
docker stop [container-id or name]

# See logs of container
docker logs [container-id or name]

# Delete container
docker rm [container-id or name]
Show Comments