What is Docker?
Docker Engine is a software service run by our operating system that enables us to create virtual "containers". Within cloud computing, it is known as a "Platform as a Service", or PaaS.
We use containers to quickly deploy software in secure, isolated environments. Containers are considered a "Software as a Service", or SaaS. Docker can interface directly with the Linux kernel and use the drivers that power our hardware. This allows most software to be deployed by Docker, regardless of the hardware used during development.
Containers are fundamentally different than a virtual machine, but they perform a similar function. Virtual machines use a "hypervisor" to emulate hardware that can them run its own operating system under the supervision of your host operating system. There is a great deal of computational resources and power overhead when emulating a virtual computer system.
Containers can be controlled like a system service, allowing us to easily start, stop or restart them. Application data like configuration and database files are stored within a persistent volume attached to our container. Updating software is easy because everything used by the application is stored within the container image.
Docker can be used to: create virtual disk drives tied to the container that can be quickly deleted when the container is stopped; mount a directory from our host computer inside the container; or create a temporary filesystem in memory that is deleted when the container is stopped.
While creating a container, we can open access to ports that allow us to communicate with the container, as well as allow containers to communicate with each other. Containers commonly use ports to offer access to a web application interface or transmit information within databases.
Docker containers are controlled primarily through the terminal. You can run a docker container from the terminal with one command.
sudo docker run --it -d -p 80:80 --name nginx -v /srv/nginx/:/config scr.io/linuxserver/nginx:latest
This command has several important parameters that define how our container is created and then functions. This command follow the basic syntax:
sudo [[command]] [[parameters]]
Running 'sudo' tells the shell to run the command as Root – or 'super user do'. We are executing the 'docker' program to 'run' a container with the following parameters:
--it | Keeps the container's shell accessible through the terminal |
-d | Runs container in the background |
-p |
Opens a port on the container, connecting a port from the container to an external port on our host computer. This allows the service to be accessible by other computers on your network. |
--name | Name to use for the container |
-v | Links a directory or file from our host computer to the container so it can access it. |
scr.io/linuxserver/nginx:latest | The Docker image to use for creating the container |
This is the basic syntax for creating any Docker container.
You can directly mount host directories, create virtual volumes within docker, or create a temporary filesystem that exists in memory but is deleted whenever the container is restarted.
Docker compose, thanks to yaml, can also increase the readability of your docker setup process.
Docker compose is a docker engine tool that allows you to define and create new containers, as well as virtual networks connecting multiple containers at once. This makes it very easy to quickly pop-up containers, as well as increases security by allowing critical components like databases to be run behind the scenes so only the container has access to it.
services:
nginx:
image: lscr.io/linuxserver/nginx:latest
container_name: nginx
volumes:
- /srv/nginx/:/config
ports:
- 80:80
Portainer allows for the easy creation of dockee compose stacks through an intuitive interface.