Docker Getting Started
1.0 Get Familiar with Docker
Here is a little introduction of how to use docker, I mainly collect snippets here for system administration of Docker.
1.1 Working With Images
Images are the starting point of your container. From the command line you can do the following.
Search for Images or use GUI: hub.docker.com
docker search ubuntu
# Search for only official images
docker search ubuntu --filter "is-official=true"
# Pull an image locally
docker pull IMAGE_ID
# View local images
docker images
# Remove an image
docker rmi IMAGE_ID
Create your Own Image (DockerFile)
# build image from docker file
# https://docs.docker.com/engine/reference/commandline/build/#options
docker build -t IMAGE_TAG DOCKERFILE_LOCATION
Create your Own Image from a container
# Create an image from a running container
docker commit -m "DESCRIPTION of modified container" -a "Author Name" CONTAINER_ID repository/new_image_name
1.2 Working with Containers
A container is a running image.
# Create a container from an image
docker run IMAGE_ID
# Create a container with interactive shell access
# https://docs.docker.com/engine/reference/commandline/run/#options
docker run --name CONTAINER_ID --hostname CONTAINER_ID -it IMAGE_NAME:IMG_VER bash
# View active images (-a for inactive too)
docker ps
# Leave an interactive container shell but keep it running
# CTRL+p CTRL+q
# Stop a docker container
docker stop CONTAINER_ID
# Start a existing container
docker start CONTAINER_ID
# Attach to a running container
docker attach CONTAINER_ID
# Remove a container
docker rm CONTAINER_ID
# create a named data-volume
docker volume create --name examine-content
1.3 Docker administration
Some handy commands when using docker.
# View connected ports of running container
docker port CONTAINER_ID
# Login to docker hub
docker login
# Delete all containers using the following command:
docker rm -f $(docker ps -a -q)
# Delete all volumes using the following command:
docker volume rm $(docker volume ls -q)
# Delete all UNUSED Images
docker image prune -af
# Delete networks (f forces)
docker network prune -f
# List Docker networks
docker network ls
# describe network
docker network inspect HASH