Docker is a collection of platform as a service (PaaS) products that use operating-system-level virtualization to deliver software in packages called containers. Containers are fully isolated from each other and are a standard unit of software that packages up code and all of its dependencies so the application runs quickly and reliably from one computing environment to another. This makes containers a great tool for reproducing development environments, as well as serving reproducible applications in production. In this quick tutorial, we’ll get started with Docker.
Install Docker for your OS.
We’ll be using Docker for Windows and the Docker docs show you how to Install Docker Desktop on Windows here.
Launch Docker and Begin The Tutorial
After the install completes you will be given the option to complete a tutorial, and that is what you should do straight away.
Clone A Repository
In order to launch a container we first need to clone a repository from Github. If you’re new to Git you can check out the Git For Beginners tutorial to become familiar. The Getting Started project is a simple GitHub repository which contains everything you need to build an image and run it as a container.
git clone https://github.com/docker/getting-started
Build The Image
A Docker image is a private file system just for your container. It provides all the files and software your container needs.
cd getting-started docker build -t docker101tutorial
Run A Container
Start a container based on the image you built in the previous step. Running a container launches your application with private resources, securely isolated from the rest of your machine.
docker run -d -p 80:80 --name docker-tutorial docker101tutorial
(Optional) Sign Up With Docker Hub
Docker hub is a wonderful resource for you to find literally any software in the world to run in your containers.
Access the world’s largest library of container images!
View Container In Dashboard
In the Docker Dashboard, you will see the container up and running with a few options. We can click the View in Browser option to see the fruits of our labor.
Your Web Browser should launch automatically and navigate to http://localhost/tutorial, which is the running application that you just launched on your local machine using Docker!
The tutorial included in the newly launched app is superb. It covers everything you need to know, and will likely answer a lot of questions you may have, especially if you are coming from a virtual machine workflow background. The following topics are covered:
- Running your first container
- Building containers
- Learning what containers are running and removing them
- Using volumes to persist data
- Using bind mounts to support development
- Using container networking to support multi-container applications
- Using Docker Compose to simplify the definition and sharing of applications
- Using image layer caching to speed up builds and reduce push/pull size
- Using multi-stage builds to separate build-time and runtime dependencies
- Docker With Visual Studio Code
Docker Quick Reference
Congratulations, you got your first container up and running. The following is a nice reference for quickly using available Docker commands.
Build an image from the Dockerfile in the current directory and tag the image
docker build -t myimage:1.0 .
List all images that are locally stored with the Docker Engine
docker image ls
Delete an image from the local image store
docker image rm alpine:3.4
Run a container from the Alpine version 3.9 image, name the running container “web” and expose port 5000 externally, mapped to port 80 inside the container.
docker container run –name web -p 5000:80 alpine:3.9
Stop a running container through SIGTERM
docker container stop web
Stop a running container through SIGKILL
docker container kill web
List the networks
docker network ls
List the running containers (add –all to include stopped containers)
docker container ls –all
Delete all running and stopped containers
docker container rm -f $(docker ps -aq)
Print the last 100 lines of a container’s logs
docker container logs –tail 100 web
Pull an image from a registry
docker pull myimage:1.0
Retag a local image with a new image name and tag
docker tag myimage:1.0 myrepo/myimage:2.0
Push an image to a registry
docker push myrepo/myimage:2.0
Docker Management
docker builder Manage builds build Build an image from a Dockerfile prune Remove build cache config Manage Docker configs create Create a config from a file or STDIN inspect Display detailed information on one or more configs ls List configs rm Remove one or more configs container Manage containers attach Attach local standard input, output, and error streams to a running container commit Create a new image from a container's changes cp Copy files/folders between a container and the local filesystem create Create a new container diff Inspect changes to files or directories on a container's filesystem exec Run a command in a running container export Export a container's filesystem as a tar archive inspect Display detailed information on one or more containers kill Kill one or more running containers logs Fetch the logs of a container ls List containers pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container prune Remove all stopped containers rename Rename a container restart Restart one or more containers rm Remove one or more containers run Run a command in a new container start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers wait Block until one or more containers stop, then print their exit codes context Manage contexts create Create new context inspect Display detailed information on one or more contexts list List available contexts rm Remove one or more contexts show Print the current context use Set the default context image Manage images build Build an image from a Dockerfile history Show the history of an image import Import the contents from a tarball to create a filesystem image inspect Display detailed information on one or more images load Load an image from a tar archive or STDIN ls List images prune Remove unused images pull Pull an image or a repository from a registry push Push an image or a repository to a registry rm Remove one or more images save Save one or more images to a tar archive (streamed to STDOUT by default) tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE network Manage networks connect Connect a container to a network create Create a network disconnect Disconnect a container from a network inspect Display detailed information on one or more networks ls List networks prune Remove all unused networks rm Remove one or more networks node Manage Swarm nodes demote Demote one or more nodes from manager in the swarm inspect Display detailed information on one or more nodes ls List nodes in the swarm promote Promote one or more nodes to manager in the swarm ps List tasks running on one or more nodes, defaults to current node rm Remove one or more nodes from the swarm update Update a node plugin Manage plugins create Create a plugin from a rootfs and configuration. Plugin data directory must contain config.json and rootfs directory. disable Disable a plugin enable Enable a plugin inspect Display detailed information on one or more plugins install Install a plugin ls List plugins push Push a plugin to a registry rm Remove one or more plugins set Change settings for a plugin upgrade Upgrade an existing plugin secret Manage Docker secrets create Create a secret from a file or STDIN as content inspect Display detailed information on one or more secrets ls List secrets rm Remove one or more secrets service Manage services create Create a new service inspect Display detailed information on one or more services logs Fetch the logs of a service or task ls List services ps List the tasks of one or more services rm Remove one or more services rollback Revert changes to a service's configuration scale Scale one or multiple replicated services update Update a service stack Manage Docker stacks deploy Deploy a new stack or update an existing stack ls List stacks ps List the tasks in the stack rm Remove one or more stacks services List the services in the stack swarm Manage Swarm ca Display and rotate the root CA init Initialize a swarm join Join a swarm as a node and/or manager join-token Manage join tokens leave Leave the swarm unlock Unlock swarm unlock-key Manage the unlock key update Update the swarm system Manage Docker df Show docker disk usage events Get real time events from the server info Display system-wide information prune Remove unused data trust Manage trust on Docker images key Manage keys for signing Docker images generate Generate and load a signing key-pair load Load a private key file for signing signer Manage entities who can sign Docker images add Add a signer remove Remove a signer volume Manage volumes create Create a volume inspect Display detailed information on one or more volumes ls List volumes prune Remove all unused local volumes rm Remove one or more volumes Commands: attach Attach local standard input, output, and error streams to a running container build Build an image from a Dockerfile commit Create a new image from a container's changes cp Copy files/folders between a container and the local filesystem create Create a new container diff Inspect changes to files or directories on a container's filesystem events Get real time events from the server exec Run a command in a running container export Export a container's filesystem as a tar archive history Show the history of an image images List images import Import the contents from a tarball to create a filesystem image info Display system-wide information inspect Return low-level information on Docker objects kill Kill one or more running containers load Load an image from a tar archive or STDIN login Log in to a Docker registry logout Log out from a Docker registry logs Fetch the logs of a container pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container ps List containers pull Pull an image or a repository from a registry push Push an image or a repository to a registry rename Rename a container restart Restart one or more containers rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save one or more images to a tar archive (streamed to STDOUT by default) search Search the Docker Hub for images start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers version Show the Docker version information wait Block until one or more containers stop, then print their exit codes
Learn More About Docker
- Get Started With Docker (docs.docker.com)
- Docker For Beginners (docker-curriculum.com)
- Get Going From Scratch In Docker (stackify.com)
- Learn To Use Docker Containers (infoworld.com)
- Simplilearn Docker Tutorial (simplilearn.com)
- Jenkov Docker Tutorial (tutorials.jenkov.com)
Docker Quick Tutorial Summary
This should give you a basic understanding of how Docker operates with a grasp of the key Docker concepts. At its most basic level, Docker is simply images and containers. Learning how to leverage these technologies is a huge benefit to software developers, small businesses, and fortune 500 companies alike.