Docker

Docker is a desktop application that supports the development of Containers and the distribution of container Images. A Container is a directory structure that contains all of the necessary dependencies to run a single application. This allows a container to be executed in isolation to a host environment.

In contrast to a Virtual Machine, which hosts an entire operating system including a kernel that executes "on top" of a virtualisation hypervisor; traditionally, executables within a container perform system calls on the kernel of the host environment.

Note: when using the "macos virtualisation framework", Docker containers may actually execute in something closer to a VM.

The following are some of the major benefits of using (Docker) containers:

  • Containers can be much smaller than dealing with full Virtual Machine images.
  • Containers can be distributed as read-only images that contain minimal or no local data when instantiated.
  • Container images can be easily uploaded to different cloud environments.
  • Because contains contain only the bare minimum to run an application, dependences can be better understood.
  • Dockerfiles allow an explicit indication of standard external dependencies versus local custom dependencies.

Docker Hub Images

Docker Hub provides a library of standard base images that can either instantiated directly or can be uses as the basis of a custom image. These can be found by searching Docker Hub.
https://hub.docker.com

For example a Ubuntu image can be instantiated by searching for "Ubuntu".

Ubuntu

For example, once Docker installed, all that is needed to instantiate a Ubuntu container is to run.

$ docker run -i -t ubuntu bash

This will cause the ubuntu container image to be downloaded - if it has not been already - and executed. Additionally, 'bash' will be executed as an interactive (-i) session and a tty will be allocated (-t). When you exit bash, the container will be removed.

In order for a container to keep running, it would seem that their needs to be a process of some sort that is still executing. At the this point is worth remembering that a contain is effectively a program that is running in a 'chrooted' environment. In other words, it is simply a program that is run like any other except that when executed its access to the host system is limited.

Some images, like the ubuntu image, need to have some program specified - bash - that will be executed within the container environment. Other images, like the MySQL image discussed below, are configured to start up a process when they are run.

References

Ubuntu Official Image | Docker Hub
https://hub.docker.com/_/ubuntu

docker run
https://docs.docker.com/engine/reference/commandline/run/

MySQL

The following content is based on the content at the MySQL reference given below. That MySQL example is intended to show how to start one container that runs a MySQL database server, and another container instance that runs the 'mysql' command line program that connects to the database; however, unfortunately, the example does not provide the required information to make the connection due to not properly explaining how the network is specified. Or there is a bug in docker which prevents it from working as explained.

The following describes what I had to do to get this working. Freeform labels begin with "my-" such as "my-mysql-network".

First create a customer bridge network by using the "docker network create {{network name}}" command. This network should be specified when each container is started.

$ docker network create my-mysql-network

Next we start the container for the MySQL server specifying the network created above. The argument "mysql:8.0.32" specifies the base image and the version to be used.

$ docker run --network my-mysql-network --name my-database -e MYSQL_ROOT_PASSWORD=my-password -d mysql:8.0.32

Next we start the contain for the 'mysql' command-line client. Importantly, we are passing 'root' as the user name as that is only account created so far. When prompted enter the password you specified above, e.g., 'my-password'.

$ docker run -it --network my-mysql-network --rm mysql mysql -h my-database -u root -p

References

MySQL - Official Image | Docker Hub
https://hub.docker.com/_/mysql

Single Host Networking for MySQL Contains on Docker
https://severalnines.com/blog/single-host-networking-mysql-containers-docker/

Docker: How to find the network container is in?
https://stackoverflow.com/questions/43904562/docker-how-to-find-the-network-my-container-is-in

PHP

References

PHP - Official Image | Docker Hub
https://hub.docker.com/_/php