Overview of 'docker run'
You can run custom images in Docker containers within Litmus Edge.
The Docker command used for this purpose is docker run and several options can be passed to this command to change its behavior. In this section, you will view some examples of how the docker run command can be used to run a Docker container in Litmus Edge.
Notes:
- The Docker run command is a very versatile tool with numerous configuration options. This section is only intended as an introduction to some of the possible uses of docker run. It does not serve as a comprehensive reference. See the Docker documentation for the official, maintained and complete description of docker run and its capabilities.
- The Run button in the Containers pane can only be used for docker run commands. Other commands, including any other docker commands, cannot be used.
The most basic example of a docker run command is docker run <image>, where <image> is the path to the image to be run in Docker.
To use options to modify the behavior of docker run, insert the option between docker run and the path to the image. docker run -d <image> adds the -d option, for example. This is called 'passing' the option to the (docker run) command.
To run a custom Docker image:
- Log in to Litmus Edge.
- From the navigation panel, select Applications. The Dashboard pane appears.
- Click Containers in the navigation sub-panel. The Containers pane appears.
Click Run at the upper-right corner of the pane. The Enter command to run text field appears.
- Enter the docker run command you wish to run into the field.
- Click Run. The command runs and the custom image container is created.
This section covers the use of the following options:
- -d or --detach
- --restart <restart options>
- -it
- --expose or -p
- --volume
- -e
Pass the -d or --detach option to docker run to run the Docker container in the background.
Important: Using the -d option is mandatory to run a Docker container in Litmus Edge.
There are several ways the --restart option can be passed to docker run.
Note: The typical approach is to pass --restart always. If this option is not set (or set differently), the container will have to be started again manually after the Litmus Edge instance is rebooted.
The -it option, when passed to docker run, starts an interactive bash shell in the container and allows the user to interact with said shell through a pseudo-TTY. This is a combination of the -t and -i options (short for --tty and --interactive respectively).
The --expose option allows the user to expose one or several ports of the container. Similarly, -p (short for --publish) publishes a container's port or ports to the host device. These options are passed by following an option by <IP address of host>:<port number> or just <port number>. For example, port X could be exposed by passing the option --expose X to docker run.
See System Requirements to review the list of required and optional ports.
You can mount and bind a volume into the container by using the --volume option ( -v for short).
The general syntax is --volume <host path of the directory to be mounted>:<mount path in container>.
You can set environment variables in the container by passing the --env option ( -e for short).
The syntax is --env <variable name>=<variable value>, where <variable name> is generally in all capital letters.