What is Docker?
Docker is a platform that uses containers to create, manage and use applications.
And what is a container? It can be considered as a package of an application, containing all the necessary dependencies and libraries needed to run the application and can be shipped as one package since they are isolated. This process is called containerization. Docker makes it possible to deploy containers in one or a cluster of Linux machines, where the containers shares resources with the host computer, unlike a virtual machine that get dedicated resources from the host. Containers are therefore preferred to virtual machines since they are light-weight and easy to deploy.
Where is docker useful?
Developers and system administrator mostly use containers to enable them isolate code and applications. It makes it easier for them to make changes to a program. Many containers can run on a single Linux computer reducing the number of systems needed and lowering overhead.
Install Docker CE in Linux Mint?
Docker is presented as a Community Edition (CE) and Enterprise Edition (EE). This guide gives a step-by-step guide on how to install ad use docker CE in Linux Mint 21.
Update your system
First ensure that your system packages are updated
sudo apt update
Install Docker dependencies and add Docker official key
APT does not use HTTPS and it is crucial to install the packages and dependencies that will enable it to use a repository through https
sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
Next add Docker official key which is important in enabling Docker repo.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/docker-archive-keyring.gpg
Adding Docker repository
Next thing is to add Docker repository to Linux Mint. The variable ‘$ (. /etc/os-release; echo “$ubuntu-codename”)’ ensures that you are using the right distribution of your Linux Mint
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(. /etc/os-release; echo "$UBUNTU_CODENAME") stable"
Update your system again
sudo apt update
Install Docker CE on Linux Mint 21
Run the below command to install the latest version of Docker CE
sudo apt -y install docker-ce
Once installed a docker group will be created. Add your user to the group who will be running docker commands.
sudo usermod -aG docker $USER
newgrp docker
Verify Docker Installation
Show docker version using the command below, the output is attached as well;
root@cloudspinxlab:~$ docker --version
Docker version 27.3.1, build ce12230
Some Docker commands
Docker is used with syntax as shown below:
docker [options] [command] [arguments]
To check options to be used with docker, run:
docker
or
docker help
Sample Output:
root@cloudspinxlab:~# docker help
Usage: docker [OPTIONS] COMMAND
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 Authenticate 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
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:
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 "/root/.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 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 "/root/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/root/.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.
For more help on how to use Docker, head to https://docs.docker.com/go/guides/
What is Docker hub?
Docker hub is a registry of docker images that can easily be pulled to run containers. An image is like a container snapshot, which when started creates a container. An image is downloaded from the hub with ‘pull’ command and run with ‘run’ command.
Example: How to run nginx with docker
Use the ‘pull’ command to get nginx image from docker hub.
docker pull nginx:latest
Sample Output:
root@cloudspinxlab:~# docker pull nginx:latest
latest: Pulling from library/nginx
2d429b9e73a6: Already exists
20c8b3871098: Pull complete
06da587a7970: Pull complete
f7895e95e2d4: Pull complete
7b25f3e99685: Pull complete
dffc1412b7c8: Pull complete
d550bb6d1800: Pull complete
Digest: sha256:0c86dddac19f2ce4fd716ac58c0fd87bf69bfd4edabfd6971fb885bafd12a00b
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
You can check the existing images by running the command below:
$ docker images
Sample Output:
root@cloudspinxlab:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 1ee494ebb83f 22 hours ago 192MB
php 8-apache 5b954d1e78b1 6 days ago 514MB
mariadb 10 73b895f9f0fd 3 weeks ago 326MB
lscr.io/linuxserver/transmission latest ea03c972a731 6 weeks ago 76.6MB
nginx <none> 3b25b682ea82 7 weeks ago 192MB
mariadb 10.11 341c6a0bbc97 2 months ago 405MB
passbolt/passbolt latest-ce cd301a6513f6 3 months ago 351MB
To run nginx we need to expose the container port to network port, in this case port 80.
docker run --name docker-nginx -p 80:80 -d nginx
Sample Output:
root@cloudspinxlab:~# docker run --name docker-nginx -p 80:80 nginx
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2024/11/27 16:26:24 [notice] 1#1: using the "epoll" event method
2024/11/27 16:26:24 [notice] 1#1: nginx/1.27.3
2024/11/27 16:26:24 [notice] 1#1: built by gcc 12.2.0 (Debian 12.2.0-14)
2024/11/27 16:26:24 [notice] 1#1: OS: Linux 6.8.0-48-generic
2024/11/27 16:26:24 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2024/11/27 16:26:24 [notice] 1#1: start worker processes
2024/11/27 16:26:24 [notice] 1#1: start worker process 29
2024/11/27 16:26:24 [notice] 1#1: start worker process 30
2024/11/27 16:26:24 [notice] 1#1: start worker process 31
2024/11/27 16:26:24 [notice] 1#1: start worker process 32
41.90.9.177 - - [27/Nov/2024:16:27:05 +0000] "GET /auth/is-authenticated.json?api-version=v2 HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36" "-"
To verify that nginx is running, open your browser and enter http://localhost. The output should be nginx welcome page
You can check all the running containers by issuing the command below. Adding -a at the end of the command displays all running containers
$ docker ps
$ docker ps -a
Sample Output:
root@gidilab:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ee81b94ec4ba nginx "/docker-entrypoint.…" 12 minutes ago Up 12 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp docker-nginx
To stop a container, take the container ID from the command above and use it to stop as below:
$ docker stop <container-ID>
This has been an informative step-by-step guide on how to install and use docker CE in Linux Mint 21. I hope it has been useful to you.
Click the links below to check on our other useful guides for your Linux installations.