Create a config from a file
In the previous step, you learned how to create a Docker config from standard input. In this step, you will learn how to create a Docker config from a file. This is a common way to manage larger or more complex configuration data.
First, let's create a simple configuration file. We will use the nano
editor to create a file named my_config_file.txt
in your ~/project
directory.
nano ~/project/my_config_file.txt
Inside the nano
editor, enter the following content:
This is the content from my config file.
Another line of configuration.
Press Ctrl + X
, then Y
, and Enter
to save the file and exit the editor.
Now that we have our configuration file, we can create a Docker config from it using the docker config create
command.
docker config create my_file_config ~/project/my_config_file.txt
In this command:
docker config create
is the command to create a new Docker config.
my_file_config
is the name we are giving to this config.
~/project/my_config_file.txt
is the path to the file containing the configuration content.
Docker will read the content from ~/project/my_config_file.txt
and create a config named my_file_config
.
To confirm that the config was created successfully, you can again list the Docker configs.
docker config ls
You should now see both my_simple_config
(from the previous step) and my_file_config
listed.