#######################
# Docker Installation #
#######################

If you don't have a Docker Engine installed, you need to do that first. 
Please, follow the official Docker Installation instructions https://docs.docker.com/engine/install/

If you are running the Docker on Windows, you need to use Linux containers.

Next you need to download the ZIP package, which includes the Docker image and the configuration files for the Modbus Server.

Extract the ZIP file to a location of your choice. 
In the next steps the path to this location will be referred to as `<installation_folder>`.

Be aware that `<installation_folder>` will be used as a mounting point to the Docker container. 
The Prosys OPC UA Modbus Server that runs inside the container will find its configuration files, 
respectively, under the folder `<installation_folder>/conf`.

See more details in the User Manual.
https://downloads.prosysopc.com/opcua/apps/ModbusServer/dist/1.4.22-31/Prosys_OPC_UA_Modbus_Server_UserManual.pdf

##################################
# Running the Docker Application #
##################################

You can run the Docker Application after you have performed the Docker Installation.

The Docker Application can only be run in Server Mode, 
which means you need to setup the configuration with the Standard or Portable Installation (in Configuration Mode). 
The easiest is to extract the Portable Installation to the same folder as the Docker Installation and
run `bin/modbusserver-config.bat` or `bin/modbusserver-config.sh`.
Then you can use the same configuration in both of them directly. 
Otherwise you will have to copy the configuration between the different installations. 

You can use the start-up script that is available under the `<installation_folder>/bin`.
The script can perform five different actions:
- `start`: Start the Modbus Server in the Docker container. Loads the image first, if it is not loaded yet.
- `stop`: Stop and remove the Docker container.
- `load`: Load the Docker image.
- `unload`: Unload the Docker image. Stops the container first.
- `status`: Current status of the Docker image, Docker container and OPC UA server.

Use `modbusserver-docker.ps1 <parameter>` or `modbusserver-docker.sh <parameter>` to
perform the action in the Docker Application in Windows or Unix-based systems, respectively.

The Docker requires Administrator privileges in Linux, so you have to run the commands with sudo.

###########################################
# Running the Docker Application Manually #
###########################################

To load the Docker image

sudo docker load -i <installation_folder>/docker-image/${docker-image-tar-link}

And then you can run the Docker image as a container:

On Unix-based systems use

sudo docker run --publish 53510:53510 --mount type=volume,dst=/data/,volume-driver=local,volume-opt=type=none,volume-opt=o=bind,volume-opt=device=<installation_folder> -e "JAVA_TOOL_OPTIONS=-Dapp.home=/data/ -Dlog4j.configurationFile=/data/conf/log4j2.xml -Dloggingoutputpath=/data/log/" -h $HOSTNAME --name modbus-server  prosys-opc-ua-modbus-server:1.4.22-31

On Windows use

sudo docker run --publish 53510:53510 --mount type=volume,dst=/data/,volume-driver=local,volume-opt=type=none,volume-opt=o=bind,volume-opt=device=<installation_folder> -e "JAVA_TOOL_OPTIONS=-Dapp.home=/data/ -Dlog4j.configurationFile=/data/conf/log4j2.xml -Dloggingoutputpath=/data/log/" -h %COMPUTERNAME% --name modbus-server  prosys-opc-ua-modbus-server:1.4.22-31

This maps the `<installation_folder>` into `/data` folder inside the container,
and also maps the access to the configuration files, respectively.
	
You can also add new options, see the official Docker run options.
https://docs.docker.com/engine/reference/commandline/run/#options

#########################
# Docker Uninstallation #
#########################

On Linux distributions, please follow the official Docker Uninstallation instructions
(CentOS) https://docs.docker.com/engine/install/centos/#uninstall-docker-engine
(Debian) https://docs.docker.com/engine/install/debian/#uninstall-docker-engine 
(Fedora) https://docs.docker.com/engine/install/fedora/#uninstall-docker-engine
(Ubuntu) https://docs.docker.com/engine/install/ubuntu/#uninstall-docker-engine

On Windows the Docker Desktop can be uninstalled through the Control Panel.

On Mac the Docker Desktop can be uninstalled from the Docker menu by selecting "Troubleshoot" and then "Uninstall*"
