CheapASPNETHostingReview.com | In this post I will explain you how to use docker with plesk onyx. Docker is a platform for distributed applications for developers and system administrators that allows running applications in containers. It enables you to use specific software, such as Redis or MongoDB, or a specific version of software, which might not be supported by your operating system or might need compiling.
Docker is installed as a Plesk component. Plesk allows you to run and manage containers that are based on specific Docker images, and to use Docker not only on the local host, but also on the specified remote machine.
Note: This functionality is not supported in Plesk installations running on Windows Server 2008.
How to Start Using Docker
If you did not select Docker when installing Plesk, you can enable it in Home > Tools & Settings > Updates & Upgrades.
To start using it, go to Docker in the left navigation panel.
The Image Catalog
In the catalog (Docker > Docker Image Catalog), Plesk displays images from https://hub.docker.com/explore. By default, only recommended images are displayed. To view more images, use the search box or filters.
For each application, multiple versions can be available. You can run a specific version by selecting the appropriate tag, as shown below:
To use filters:
- Click the arrow next to the search box.
- Specify both or one of the following: image name and repository.
The repositories that you can select:
- Local repository – contains local images. These are images that were already downloaded and now stored on the server with Docker. For details, see Managing Local Images further in this section.
- Docker Hub – https://hub.docker.com/explore.
To run a container:
- Go to Docker > Docker Image Catalog.
- Use the search box or filters to quickly find applications in the catalog.
- To view application description and documentation on Docker Hub, click the image name. This does not apply to local images.
- To run a specific version, click the arrow next to the Run button, and select the application version.
- To run the latest version of the selected application, click Run.
If the image is stored locally, the button looks like Run (local).
Plesk creates a container and prompts you to specify its settings, such as environment variables, and then runs it. You can cancel running by clicking Cancel on the Settings screen. For details about the settings, see Container Settings further on this page.
- The container appears in the list of containers at the top of the Docker Catalog page.
See the log (Logs) to find out what settings the container needs to run successfully.
Note: If you want to change container settings, you do not need to stop the container: When you save new settings, Plesk recreates the container.
To edit container settings, go to Settings or Details > Settings.
Automatic Start
If the option Automatic start after system reboot is not selected, then after system reboot the websites that use this container might be down, and you will need to start the container manually.
Port Mapping
By default, Automatic port mapping is turned on and the container’s internal port is mapped to a random port on the host system (for example, 32768).
To change the port on the host system, clear the option Automatic port mapping and specify another external port in Manual mapping. If no Manual mapping appears when you clear the check box, it means that the container does not expose ports.
Volume Mapping
Docker volumes are directories on your server mounted to a Docker container, so that you have persistent storage that can be accessed from your host system. The data in Docker volumes can be backed up, and, more important, it is not deleted when you stop or delete a container.
To add a volume mapping, specify the following:
- In the first (left) box – the path to the directory on the server that you want to mount to the container.
- In the second (right) box (marked as Source) – the path to a directory inside the container.
To map more directories, click Add Mapping.
Setting Environment Variables
Environment variables are used by the application inside a container. You might need to add more variables or edit existing variables. Plesk allows you to add as many variables as required.
Operations with Containers
You can do the following with containers:
- Restart (Restart) or stop (Stop) a container. In these cases, the container will be recreated with the current settings.
Note: If you did not save the data to the mounted volumes (see the Volume Mapping section below), the data will be lost.
- View logs and resource consumption (Details).
- Change container settings, such as environment variables or volume mapping (Settings or Details > Settings).
In Plesk on CentOS, you can set a memory limit for a container (Settings > Memory limit).
- Rename a container (Settings > Container name).
- Recreate a container using the same or another version of the image (Details > Recreate).
- Create an image based on a container with your custom settings (Details > Save as Image).
- Take a snapshot of a container (Details > Download a Snapshot).
- Remove a container (Remove or Details > Remove).
Recreating a Container
Usually, you need to recreate a container when you want to update the application to a newer version. In fact, you can rebuild a container using any application version available in the catalog, not only a newer one.
Custom settings are preserved during recreation. To preserve data used by the application inside a container, you should specify volume mapping before you recreate a container. Volume mapping enables you to have access to directories used inside a container
To recreate a container:
- Go to Docker and click Details below the container you want to recreate.
- Click Recreate in the container settings and specify the image version, and whether to use default environment variables.
Using Remote Docker
By default, Plesk uses Docker installed as a Plesk component. However, you can use one or more Docker services installed outside of Plesk. Note that you can use only one service at a time. The hostname of the selected server is displayed in the title of Docker Catalog in Plesk.
Important: Managing remote Docker services requires a Plesk license key add-on. Without this add-on, you can only manage the local Docker service, which is running on the Plesk server.
Configuring Remote Services
Configure the remote server that runs Docker as described in the Docker documentation to use it as a remote server in Plesk.
Managing Remote Services
The following steps are applicable to both Plesk for Linux and for Windows.
To start using Docker that runs on a remote host:
- Go to Tools & Settings > Docker (under Server Management).
- Click Add Server and specify the settings of the remote server with Docker.
- To start using this Docker service in Plesk, leave Set active selected.
The link to Docker will appear in the left navigation panel.
To switch between Docker services:
- Go to Tools & Settings > Docker (under Server Management).
- In the list of servers select the server that you are going to use and click Set Active.
Alternatively, you can set the server as active while editing its settings.
Creating Images with Custom Settings
If you want to create a new image based on the changes that you made to the contents of a container, use the Save as Image command. It takes a snapshot of your container, which appears as a new image in the image catalog. In this way, you can create images with custom settings such as environment variables.
To create an image from one of your containers:
Go to Docker > Details under the container name > Save as Image, and optionally specify:
- Image name. By default, an ID will be generated and used as the name.
- Tag. You can specify the image version here. By default, the version will be “latest”.
The created image appears in the image catalog and is marked Local image.
Managing Local Images
Local images are images that are stored by Docker on local disk, so there is no need to download them from the Image Catalog.
An image becomes local in the following situations:
- You selected any version (tag) of an image and the image started downloading. Either you later run a container or cancel running (in the Settings screen), the image is saved locally.
- You upload an image to Docker catalog in Plesk (Upload Image in Docker Image Catalog).
- You created a custom image from a container
- You built an image using the command-line interface.
If Docker has at least one downloaded version from a group of versions belonging to an image, this image is marked Local image in the catalog. Run (local) means that the latest version was already downloaded. Plesk also shows how many local images exist for a product.
To view local images and remove outdated local images:
- Go to Docker > Docker Image Catalog.
- To find all local images, click the arrow next to the search box and select Local in the Repository filter.
- To view all local images of a specific product, click the link under the product name. All local images’ tags and occupied disk space will be displayed.
- To remove all images, click Clean All Images.
- To remove a specific image, click the Remove [wp-svg-icons icon=”close” wrap=”i”] icon next to the image that you want to remove
Setting up nginx to Proxy Requests from Domains to a Container
Some Docker containers expose ports so that applications in containers could be accessible via those ports.
When you use an application in Docker container on your website, you may find inconvenient to specify the non-standard port in its URL. To avoid inconvenience, you can set up nginx to proxy requests from domains to that port, so domains can use a standard port (such as 80) and there is no need to explicitly specify the port in URL.
Requirements
- nginx must be running in Plesk.
- You must map the port inside a container to some port on the host system (for example, 32768) manually (Docker > select a container > Settings > clear the option Automatic port mapping).
After you have mapped the port inside a container manually to some port on your system (for example, 32768), you can set up nginx to proxy requests from domains to that port, so domains can use a standard port on nginx (for example, 80). To make it possible, add a rule for nginx in the domain settings in the following way:
Go to Websites & Domains > the domain > Proxy Rules > Add Rule and specify the following:
- URL. Specify the URL of the website that uses an application running in a container. It can be either the main website or a part of it.
- Container. Select the application running as a Docker container.
- Port. Select one of the mappings that was specified in the container settings (a port inside a container mapped to a port on your system). Nginx will proxy requests to the port on the system.