Need input with passing commands in Kubernetes containers
The YAML list definition are only a matter of taste, it's just a YAML syntax. This two examples are equivalent:
listOne:- item1- item2listTwo: ['item1', 'item2']
And this syntax works for both args and command. Beside that args and command are slight different, as the documentation says:
- If you do not supply command or args for a Container, the defaultsdefined in the Docker image are used
- If you supply a command but no args for a Container, only the supplied command is used. The default EntryPoint and the default Cmd defined in the Docker image are ignored.
- If you supply only args for a Container, the default Entrypoint defined in the Docker image is run with the args that you supplied.
- If you supply a command and args, the default Entrypoint and the default Cmd defined in the Docker image are ignored. Your command is run with your args.
Imagine a container like mysql, if you look it's Dockerfile you'll notice this:
ENTRYPOINT ["docker-entrypoint.sh"]CMD ["mysqld"]
The entrypoint call a script that prepare everything the database needs, when finish, this script calls exec "$@"
and the shell variable $@
are everything defined in cmd.
So, on Kubernetes, if you want to pass arguments to mysqld you do something like:
image: mysqlargs:- mysqld- --skip-grant-tables# or args: ["mysqld", "--skip-grant-tables"]
This still executes the entrypoint but now, the value of $@
is mysqld --skip-grant-tables
.