What is docker and docker compose?These are the concepts you must know!

Mondo Health Updated on 2024-01-30

In the later software installation, we will use docker and docker-compose, in order to help you understand these two tools, this article will first give a brief introduction.

In a nutshell, Docker and Docker Compose are two tools that make it easier for us to build and run applications in a Linux environment. Here we take the installation of WordPress as an example to illustrate.

Docker is a technology that allows you to package your WordPress application and the environment it needs (e.g. php, mysql, etc.) into a small box called a container. The good thing about a container is that it can run on any Linux machine that supports Docker without worrying about differences and conflicts in the environment. This allows you to move and deploy your WordPress app and environment together without having to reinstall and configure it each time.

At the heart of Docker is the Docker Engine, which is a client-server application that runs on a Linux machine and is responsible for creating and managing containers. The Docker engine consists of the following parts:

The Docker client, which is a command-line tool that allows you to interact with the Docker engine and perform various actions such as creating, running, stopping, deleting containers, and more.

The docker server, which is a background process, can receive requests from docker clients and perform the management and operation of containers.

Docker image, which is a read-only template that contains all the files and configuration of a container, can be used to create containers. You can make an image from Docker Hub or other repositories, or you can make your own and upload it to the repository.

A Docker container, which is an independent runtime environment created based on a Docker image, can run one or more processes. You can use the docker client to start, stop, enter, exit, and delete containers.

Docker networking, which is a virtual networking layer that allows containers to communicate with each other or between containers and the outside. You can use the Docker client to create, view, modify, and delete networks.

Docker volumes, which are a persistent data layer that allows containers' data to be shared and stored between containers or between containers and hosts. You can use the docker client to create, view, modify, and delete volumes.

Here's how docker works:

First, you need to install the Docker engine on your Linux machine and then start the Docker server.

You can then use the Docker client to make the Docker images you need, such as WordPress images and MySQL images.

Next, you can use the Docker client to create and run the Docker containers you need, such as WordPress containers and MySQL containers, and set up network connections between them.

Finally, you can use the Docker client to manage and manipulate your Docker container, such as starting, stopping, deleting the container, or going inside the container to operate.

Docker Compose is a tool that allows you to manage multiple containers with a single file. For example, your WordPress application might need a web container and a DB container to run a WordPress program and a MySQL database, respectively. If you're only using docker, you may need to create and launch both containers separately, and then set up the connection between them as well. If you're using docker compose, you just need to write down the configuration of the two containers in a single file, and then use a single command to create and start them together, and the connection between them will be set up automatically. This will make it easier for you to manage and run your WordPress app.

At the heart of docker compose is docker-composeA YML file, which is a YAML file that can define one or more services, each corresponding to a container. In this file, you can specify the mirror, port, network, volume, environment variables, and other configurations for each service. You can also define some dependencies, boot order, extension rules, and other options in this file.

The workflow of docker compose goes like this:

First, you need to install docker compose on your linux machine, and then write docker-composeYML file to define the services and configuration of your WordPress app.

You can then use the docker-compose command to create and launch your WordPress app, such as the docker-compose up command.

Finally, you can use the docker-compose command to manage and manipulate your WordPress application, such as the docker-compose stop command to stop the application, or the docker-compose logs command to view the logs.

Docker Hub is an official public Docker image repository provided by Docker Inc., which allows users to store, share, and obtain Docker images, which are files used to create and run Docker containers. Docker Hub is the world's largest Docker image repository, which contains more than 100,000 Docker images from software vendors, open source projects, and community developers, covering a variety of common applications and services, such as databases, web servers, application frameworks, etc. The main features of Docker Hub are:

Store and manage Docker images: Users can create their own repositories on Docker Hub to store and manage their own Docker images, and can also pull or push Docker images from other users' repositories. Users can choose to make their own repositories public or private, as well as set access rights and collaboration members for repositories.

Build and distribute Docker images: Users can configure automated builds on Docker Hub to automatically create and update Docker images based on the user's source** or other Docker images. Users can also distribute their own Docker images on Docker Hub, which can be used by other users or platforms to use or deploy their own applications or services.

Discover and use Docker images: Users can search and browse various Docker images on Docker Hub to find and use the applications or services they need. Users can view the details of the docker image, such as description, tags, size, update time, number of times, ratings, reviews, etc., as well as the source or documentation of the docker image, as well as a guide on how to use or run the docker image.

In the later software installation, the docker image we use is retrieved and ** from the docker hub repository.

Related Pages