Docker Parameters – The Best Parameters!

If you are an experienced system administrator, you may have heard of "Docker" heard and already know what it is. For those who don't know, Docker is an open source technology that allows applications to run in isolated containers.

What is a Docker parameter?

A Docker parameter is a value that is passed to a Docker command. This value can be specified either in the form of an environment variable or directly in the command itself.

The different types of Docker parameters

The docker run command has many different options and parameters that you can customize to suit your needs. In this Article We will focus on the different types of Docker parameters.

There are four main types of Docker parameters: environment variables, single commands, combinations of commands and files. Each type has its own Advantages and disadvantagesthat need to be taken into account.

Environment variables are easy to use and allow you to customize certain parts of your environment without having to change your code. However, they are only capable of storing simple data types, which means they are not suitable for more complex application configurations.

Single commands allow you to simply execute a command without having to create a file. This can be useful if you just want to perform a specific action without building a full application. However, individual commands are not scalable and may therefore be unsuitable for larger applications.

Combinations of commands allow you to save multiple commands in a file and then execute them. This is useful when you want to perform multiple actions without having to change the code each time. However, combinations of commands are often confusing and difficult to debug.

Files are the most flexible way to store and run your code. Files can be easily created and modified, meaning they are suitable for all types of applications. However, files are often confusing and difficult to debug.

The best Docker parameters

The best Docker parameters

If you use Docker, you can specify a variety of options to control the behavior of the container. This article explains the best and most commonly used Docker parameters.

–name: This parameter gives the container a name. If you don't specify a name, a random name will be generated. The name should be unique so that you can easily identify the container.

–detach / -d: This parameter runs the container in the background. By default, the container runs in the foreground and the command line remains blocked until the container exits or is canceled with Ctrl+C. If you want to run the container in the background, you should specify the –detach parameter.

–publish / -p: This parameter establishes a connection between a container port and a host port. If you don't connect, you won't be able to reach the container's port from outside. If you want to publish multiple ports, you can specify the –publish parameter multiple times.

–interactive / -i: This parameter ensures that the container runs in the foreground and the command line is not blocked until the container exits or is aborted with Ctrl + C.

–tty / -t: This parameter simulates a terminal in the container. Specifying this parameter allows you to type into the container and execute commands. If this parameter was not specified, it will not be possible to type into the container or execute commands.

–rm: This parameter deletes the container after it exits. If you do not specify this parameter, the container will remain intact and can be restored later.

–volume / -v: This parameter creates a connection between a host folder and a container folder. When you connect, you can copy files from the host folder to the container and vice versa.

–workdir / -w: This parameter sets the working directory in the container. By default the working directory is set to /root.

–user / -u: This parameter sets the user in the container. By default the user root is used.
These are just a few of the many Docker parameters available. For more information, see the Docker documentation.

–restart: This parameter specifies how Docker should restart a container if it quits or crashes. There are different options for this parameter: no, on-failure, always and unless-stopped. The default is “no”, which means the container will not be restarted. If you specify “on-failure”, the container will restart if it is running with a Error is terminated (e.g. due to a crash). “Always” means that the container will always be restarted - even if it was shut down cleanly. “Unless-stopped” is similar to “always”, but here the container is not left running unattended; Once you run the “docker stop” command to stop the container, it will no longer restart.

–hostname: As the name suggests, this parameter sets the hostname of the container. The default is the name of the container, or a random name if no –name is specified.

–interactive or -i: This parameter allows you to log into and interact with a running container. For example, you can start a terminal in the container and run commands. If you do not specify this parameter, you will not be able to log in and interact with the container.

–volume or -v: This parameter creates a connection between a host folder and a container folder. When you connect, you can copy files from the host folder to the container and vice versa.

Advantages and disadvantages of a Docker parameter

Arguably the most important benefit of a Docker parameter is that it increases the flexibility and adaptability of an application. For example, specific environment variables can be passed to a specific application. Access to host system resources can also be controlled via the parameter.

Another advantage is that certain security functions can also be bound to an application using Docker parameters. For example, it can be ensured that only authorized users can access an application.

One disadvantage of Docker parameters is that they are typically only available to developers and system administrators. They are usually not visible or understandable to normal users. Therefore, it can be difficult to customize an application if you don't know the Docker parameters.

Docker run reference

Most Docker commands start with the “docker” command followed by a subcommand. docker run is a typical subcommand and is used to run a new container.

The docker run command has many different options and parameters that you can specify to create and configure the container you want to run. In this article, we will look at the best parameters for the docker run command.

Operator exclusive options

Most operator options are not exclusive to operators, but are also available to other users. However, there are a few options that are intended exclusively for operators. These include:

–log-level : Sets the logging level. Only operators have access to this option to customize logging for their installation.

–storage-opt : Allows the operator to configure additional storage options for their installation. This is useful when the operator uses a specific storage backend that is not supported by Docker.

–format : Allows the operator to customize the format of docker info output. This is helpful if the operator wants to further process the information in a specific form.

Detached vs foreground

When you run a container with the docker run command, it always runs in the foreground. This means that the container has the Console of the host system and you cannot exit the command without stopping the container.

If you want to run a container in the background (detached), you can do this with the “-d” parameter. The container is then executed in its own process and control of the console is given back to the host.

Container identification

The container ID is a unique identifier for a Docker container. It can be viewed using the docker ps command and is typically eight characters long. The first three characters of the container ID are the ID of the image that created the container.

UTS settings (–uts)

UTS mode specifies how a container should manage its own identity. Typically, each container gets its own UID and GID. However, this mode does not always make sense, especially when multiple containers are accessing the same one Database or need to access other resources. In this case, you can disable UTS mode so that all containers have the same UID and GID.

IPC settings (–ipc)

The IPC setting (–ipc) allows using a common area for communication between containers. This allows two or more containers to access the same files and sockets. If you don't specify an IPC setting, Docker will set a default range for communication.

Network settings

There are some useful parameters in Docker that you should know. One of these parameters is –net. This parameter determines how the network is configured for a specific application.

–net=host – This option allows a container to access the host’s network directly. This means the container has access to all network services (DNS, HTTP, etc.) provided by the host.

–net=bridge – This option creates an internal network bridge container that allows the specified container to communicate with other containers and the host. This is the default option for –net.

–net=container: – This option allows a container to be connected to another container that uses the same network option. For example, one could connect two containers with the same –net=bridge option to connect them together.

–net=none – This option disables networking for a container. A container that uses this option does not have access to the network and therefore cannot use network services.

To allow two containers to communicate with each other, you can use the docker network create command:

$ docker network create my-network

This command creates a new network named my-network. To connect a container to this network, one can use the docker run command with the –net option:
$ docker run –net=my-network…

To remove a container you can use the docker rm command:

$ docker rm my-container

This command removes the my-container container. To remove a network you can use the docker network rm command:
$ docker network rm my-network

This command removes the network named my-network.

Restart policies (–restart)

Docker's restart policy specifies how a container restarts after a Error should be restarted. The restart options are:

–restart=no: The container will not be restarted.
–restart=always: The container is always restarted, even if it was closed cleanly.
–restart=on-failure: The container will be restarted if it is running with a Error was ended.
–restart=unless-stopped: The container is always restarted unless it was stopped manually with the docker stop command.

Exit Status

Exit status is a value returned by a command or function to indicate whether the command or function completed successfully.

If a command completes with an exit status of 0, it usually means that the command was successful. A different exit status usually means that the command failed.

Exit statuses can also be used to generate specific error codes. This can be helpful if you have a specific Find and fix errors want. For example, exit 1 can be used to display a “File not found” error.

Clean up (–rm)

Most Docker commands take one or more parameters. One of the most important is “–rm”. This command ensures that all temporary objects created by Docker are deleted after the command completes. This ensures that no unwanted objects remain in your environment.

Security configuration

Security configuration is a very important aspect when working with Docker. This section lists some of the most important parameters for the Safety presented by Docker.

First of all, you should always be aware that Docker Containers are sealed off, but not isolated. This means that if an attacker gets into one container, they can access all other containers and the host system. Therefore, it is very important that you properly configure and secure your containers.

One of the most important parameters for Docker security is “–cap-add”. This parameter allows you to pass certain kernel capacities to the container. This allows you to control access to certain features of the host system, thereby increasing security. For example, you can use “–cap-add=NET_RAW” to ensure that a container cannot sniff network packets.

Another important parameter is “–security-opt”. This parameter allows you to restrict access to certain features of the host system. For example, you can use “–security-opt=apparmor:unconfined” to ensure that AppArmor is not applied to the container. This gives attackers a huge advantage as they are no longer restricted by AppArmor.

Another very important parameter is the SELinux “–label” parameter. This parameter allows you to control access to certain features of the host system. For example, with “–label=type:
container_runtime_t” ensure that Docker does not apply SELinux to the container. This gives attackers a big advantage because they are no longer restricted by SELinux.

The last important parameter is “–privileged”. This parameter allows you to gain access to all functions of the host system. This is very dangerous and should only be used when absolutely necessary.

That's it for today! We hope this article helped you Basics to understand Docker.

Specify an init process

The Docker Daemon accepts a specified init process as an argument. This process is the first process to run in the container. If no init process is specified, the default init process init is used.

The specified init process should ensure that only a single process is running in the container. When multiple processes are running, unpredictable errors may occur. The specified init process must also ensure that the container shuts down properly when it exits.

Specify custom cgroups

If you want to set a custom cgroup memory limit for your application, you can do so with the –cgroup-memory flag. For example, if you want to set the limit to 512 MB:

–cgroup-memory=”512m”

How do I configure a custom DNS server for my containers?

If you have a custom DNS server, you can set this in your Application Specification File or the dcos marathon app add command. This example shows how to set a DNS server using the application specification file:

{ “id”: “/my-service”, “dns”: { “nameservers”: [ “10.0.0.1” ] } }

This example shows how to set a DNS server using the dcos marathon app add command:
$ dcos marathon app add { “id”: “/my-service”, “dns”: { “nameservers”: [ “10.0.0.1” ] } }

For more information about DNS, see DNS Settings in the Marathon documentation.

How do I configure a custom search domain for my containers?

If you have a custom search domain, you can set this in your Application Specification File or the dcos marathon app add command. This example shows how to set a search domain using the application specification file:

{ “id”: “/my-service”, “dns”: {“search”: [ “.example.com” ] } }

This example shows how to set a search domain using the dcos marathon app add command:$ dcos marathon app add { “id”: “/my-service”, “dns”: { “search”: [ “.example.com” ] } }

For more information about DNS, see DNS Settings in the Marathon documentation.

How do I configure a custom network for my containers?

If you have a custom network, you can set this in your Application Specification File or the dcos marathon app add command. This example shows how to set a network using the application specification file:

{ “id”: “/my-service”, “networks”: [ { “mode”: “container/bridge” } ] }

This example shows how to set a network using the dcos marathon app add command:
$ dcos marathon app add { “id”: “/my-service”, “networks”: [ { “mode”: “container/bridge” } ] }
For more information about networks, see Networks in the Marathon documentation.

Runtime constraints on resources

“Runtime constraints on resources” is a Docker parameter that controls resource management for a running container. This parameter allows you to limit the CPU usage, memory footprint, and file system for a container.

User memory constraints

Most Docker parameters are dedicated to managing main memory. This is primarily used for running containers and images. There are also some other parameters for network configuration and others Resources are responsible.

Docker's main memory is very limited. So if you want to create a container or image, you need to specify these parameters. Otherwise, you may experience performance issues or image download errors.

If you want to increase the storage space of a container, you can run the following command:

docker run -it –memory=”4g” ubuntu /bin/bash

This command creates a new container with 4GB of RAM. If you need more memory, you can increase the value accordingly.

Alternatively, you can run the following command to create an image with more memory:

docker build –memory=”4g” -t my_image .

This command creates a new image with 4GB of RAM. If you need more memory, you can increase the value accordingly.

Kernel memory constraints

The kernel memory constraints are an important parameter for Docker. They determine how much kernel memory a container can use. If you do not specify the value of this parameter, the default value is used.

If you want to adjust the value of the kernel memory parameter, you must first find the current value. This can be done using the “docker info” command. You can then specify the new value you want.

Note that changing this parameter may require restarting the container.

Swapiness constraint

The swappiness setting is a value between 0 and 100 that determines the frequency with which the system writes memory contents to swap space. A high swappiness value means that swapping occurs more frequently and vice versa. The default is 60. For Databases Lower swappiness is generally recommended to ensure memory stays in memory for as long as possible.

CPU share constraint

CPU utilization share is a construct built into the Linux kernel that Docker uses to ensure that a container does not use more than the specified number of cores. This is important for isolation between containers and the host, as well as for the reliability of the entire system.

Cpuset constraint

A CPUset constraint places a limit on the number of CPUs a container can use. This is useful to ensure that a container does not interfere with other containers on the host system.

CPU quota constraint

CPU quota limiting (cgroup_cpu_shares) is a Linux kernel feature that allows limiting CPU usage between different processes. This parameter can be specified in Docker using the “–cpu-shares” command.

For example, if you specify a value of 512, the container will receive twice the CPU time as a container with a value of 256. So specifying a high value does not necessarily mean that the container will receive more CPU time, but only relative to other containers with lower values.

Block IO bandwidth (Blkio) constraint

Block IO bandwidth throttling is a tool that allows you to limit the bandwidth of I/O throughput for a container. This is useful to ensure that a container does not overload other containers on the host. Block IO bandwidth is measured in bytes per second and can be set for all devices or for a specific device.

–blkio-weight

The blkio weight indicates how much I/O bandwidth a container receives from the entire system. For example, if you specify a value of 100, the container will receive twice the I/O bandwidth compared to another container with the default value of 50. This parameter is useful if you want to ensure that a particular container achieves optimal performance.

Additional groups

If you want to run multiple services in a single container, you can create additional groups. This is useful if, for example, you want to run a web server and a database server in a single container. To create an additional group, add the following command to the docker run command: –group-add .

Runtime privilege and Linux capabilities

The “runtime privilege” is a Linux core function that allows certain permissions to be changed during runtime. This is particularly useful when an application requires different permissions to start or run.

You can use this function with the “sudo” command. For example: sudo chmod 777 /path/to/file. This command gives all users full access to the specified file.
However, there are some limitations regarding the sudo function. For example, users cannot change permissions that they do not already have. This is a security precaution to prevent users from assuming permissions they shouldn't have.

Another disadvantage of the sudo function is that it has to be re-run for each command. If a user often has to execute commands with different permissions, this can be very annoying.

Linux Capabilities is an extension of the Linux kernel that allows specific permissions to be set Program and applications to assign. This allows users to set permissions for a program or application and change those permissions if necessary.

Much more flexible than the sudo function, Linux Capabilities allows users to fine-tune permissions on a program or application. For example, a user with Linux Capabilities can set permissions so that a program can only access files as read. This is very useful for ensuring that a program doesn't make changes to files that it shouldn't.

Linux Capabilities is also much more user-friendly than the sudo function. With Linux Capabilities you don't have to set permissions for every command. One can simply install a program or application and then set the permissions for that program or application.

Logging drivers (–log-driver)

When you build a Docker image, you can specify which logging driver to use. The default logging driver is “json-file”. However, there are a variety of other options. Some examples are syslog, journald and fluentd.

You can specify the logging driver with the “–log-driver” parameter. For example, if you want to use the syslog logging driver, you can do it like this:

docker run –log-driver=syslog…

This parameter is very useful if you want to store your containers' logs in a centralized logging system.

Overriding Dockerfile image defaults

When you create a new Docker image, you can override the default settings for that image. This is useful if you want to change specific settings without rebuilding the entire image. For example, you can change the default username for a new image without rebuilding the entire image.

To change the default values ​​for a new Docker image, you must first create a file called “.dockerignore” in your project directory. In this file you should specify all directories and files that should be ignored when creating the image. Once you have created this file, you can run the following commands to create your image:

docker build -t your_image_name .
This command creates a new Docker image named “your_image_name” and overwrites any default defined values.

Conclusion

The best Docker parameters depend largely on your needs. In this article we have introduced some of the most important parameters that are relevant to most use cases. Of course, there are many other great options not mentioned in this article. Take the time to research all the options and see which ones work best for you!

Note..is important!

All external sites linked on this website are independent sources. 
These links are not sponsored and no financial contribution was received for their inclusion. 
All information on this website is provided without guarantee.
This site is a private project by Jan Domke and solely reflects personal opinions and experiences.

Jan Domke

Prompt Engineer | Social Media Manager | Hosting Manager | Web administrator

I have been running the online magazine privately since the end of 2021 SEO4Business and thus turned my job into a hobby.
I have been working as a since 2019 Senior Hosting Manager, at one of the largest internet and marketing agencies in Germany and am constantly expanding my horizons.

Jan Domke