Docker is a platform that enables you to create, deploy, and run applications in containers.
Containers are similar to virtual machines in that they provide an environment for running applications, but they are more lightweight and efficient because they share the host operating system's kernel. They are created from images, which are templates that include all required files and dependencies for your application.
Docker containers provide a way to package an application and its dependencies into a single unit that can run consistently across different environments.
In this tutorial, we will guide you through the installation process of Docker on an Ubuntu 22.04 server from AlphaVPS.
For a performant experience, we highly advise running Docker on our KVM-based services, which come with their own dedicated kernel.
They can be viewed at https://alphavps.com/ryzen-vps.html & https://alphavps.com/high-performance-vps.html
Docker is also able to run on OpenVZ-based services, but do note that support is limited.
Installing Docker
We will install Docker from the official Docker repository. To do this successfully, we will need to perform a few prerequisites.
Follow these steps:
1. Update your apt cache
sudo apt update
2. Install prerequisites
sudo apt install apt-transport-https ca-certificates curl software-properties-common
3. Add the GPG key for the official Docker repository
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
4. Add the repository to your apt sources
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
5. Update your apt cache again with the new additions
sudo apt update
6. Install docker
sudo apt install docker-ce
7. Confirm the installation
sudo systemctl status docker
You will receive a similar output:
The installation is now completed and you are provided with access to the docker
command line tool - the so-called docker client.
A short introduction to the docker client
The Docker command-line interface (CLI), is a command-line tool that allows you to interact with the Docker daemon and manage Docker containers, images, networks, and volumes.
With it, you are able to run and manage containers, build and push Docker images, create and manage networks and volumes, and view logs and statistics for running containers.
The docker
command is commonly used with the following syntax:
docker [option] [command] [arguments]
By running docker
, you are able to inspect every available subcommand for it.
docker
You will receive a long list of available subcommands with description, and global options.
A self-sufficient runtime for containers
Common Commands:
run Create and run a new container from an image
exec Execute a command in a running container
ps List containers
build Build an image from a Dockerfile
pull Download an image from a registry
push Upload an image to a registry
images List images
login Log in to a registry
logout Log out from a registry
search Search Docker Hub for images
version Show the Docker version information
info Display system-wide information
Management Commands:
builder Manage builds
buildx* Docker Buildx (Docker Inc., v0.10.4)
checkpoint Manage checkpoints
compose* Docker Compose (Docker Inc., v2.17.3)
container Manage containers
context Manage contexts
image Manage images
manifest Manage Docker image manifests and manifest lists
network Manage networks
plugin Manage plugins
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes
Swarm Commands:
config Manage Swarm configs
node Manage Swarm nodes
secret Manage Swarm secrets
service Manage Swarm services
stack Manage Swarm stacks
swarm Manage Swarm
Commands:
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
events Get real time events from the server
export Export a container's filesystem as a tar archive
history Show the history of an image
import Import the contents from a tarball to create a filesystem image
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
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
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
save Save one or more images to a tar archive (streamed to STDOUT by default)
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
wait Block until one or more containers stop, then print their exit codes
Global Options:
--config string Location of client config files (default "/home/vladislav/.docker")
-c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker
context use")
-D, --debug Enable debug mode
-H, --host list Daemon socket(s) to connect to
-l, --log-level string Set the logging level ("debug", "info", "warn", "error", "fatal") (default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default "/home/vladislav/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/home/vladislav/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/home/vladislav/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
Run 'docker COMMAND --help' for more information on a command.
You are able to view the options for each subcommand by running:
docker `docker-subcommand` --help
Make sure that you replace docker-subcommand
with a proper subcommand.
An example command would be:
docker create --help
The provided partial output would be:
Usage: docker create [OPTIONS] IMAGE [COMMAND] [ARG...]
Create a new container
Aliases:
docker container create, docker create
Options:
--add-host list Add a custom host-to-IP mapping (host:ip)
-a, --attach list Attach to STDIN, STDOUT or STDERR
--blkio-weight uint16 Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
--blkio-weight-device list Block IO weight (relative device weight) (default [])
--cap-add list Add Linux capabilities
--cap-drop list Drop Linux capabilities
--cgroup-parent string Optional parent cgroup for the container
--cgroupns string Cgroup namespace to use (host|private)
'host': Run the container in the Docker host's cgroup namespace
'private': Run the container in its own private cgroup namespace
'': Use the cgroup namespace as configured by the
default-cgroupns-mode option on the daemon (default)
System-wide information about docker can be viewed by running:
docker info