Docker on Centos 7: Resolving “unknown flag” Error with --ip-forward
When attempting to start the docker
service after installing it from the official repository for CentOS 7 as per Docker’s installation instructions, encountering an unexpected error was a frustrating experience:
Starting Docker Application Container Engine...
docker[24207]: unknown flag: --ip-forward
docker[24207]: See 'docker --help'.
docker[24207]: Usage: docker [OPTIONS] COMMAND
Here’s how the situation unfolded and was ultimately resolved. The Docker version on CentOS 7 in use at that time was Docker version 24.0.6, build ed223bc
. An investigation revealed an overlooked file causing this issue: /etc/systemd/system/docker.service.d/service-overrides.conf
which erroneously injects additional environment variables into the service’s ExecStart
, including --ip-forward
:
# cat /etc/systemd/system/docker.service.d/service-overrides.conf
[Service]
EnvironmentFile=-/etc/sysconfig/docker
EnvironmentFile=-/etc/sysconfig/docker-storage
EnvironmentFile=-/etc/sysconfig/docker-network
ExecStart=
ExecStart=/usr01/.localbin/docker daemon $OPTIONS \
$DOCKER_STORAGE_OPTIONS \
$DOCKER_NETWORK_OPTIONS \
$BLOCK_REGISTRY \
$INSECURE_REGISTRY
To fix this, the leftover service-overrides.conf
file was removed and a reboot followed to get Docker up and running smoothly once again:
-
Remove offending service configuration override with root permission via command line (or using appropriate permissions if not logged in as root):
sudo rm /etc/systemd/system/docker.service.d/service-overrides.conf
-
Restart the Docker daemon:
systemctl restart docker
-
(Optional) Reboot your CentOS machine for good measure, especially if you suspect residual issues from previous configurations or installations which may not require it in this specific scenario but is a common practice when resolving service-related problems on Unix systems:
reboot
After these steps were taken and the system was restarted either manually through reboot
command, Docker started correctly without any further errors. This incident highlights that attention to configuration files can be just as crucial in service management for containerized environments on Linux-based systems like CentOS 7. Remember always checking your configurations against official guides and being aware of previous installation remnants when troubleshooting system services!