Jack Wallen shows you how easy it is to use environmental variables in your container with the Portener Management Platform.
Environmental variables are an important part of the container puzzle. This feature allows you to specify the variables required for the container to be placed. For example, suppose you are going to set up a full-stack application that relies on MySQL. You may want to be able to define things like databases, passwords and users for that installation. To do this, you use environment variables.
Views: Recruitment Kit: Back-end Developer (TekriPublic Premium)
When environment variables are used in a command-line deployment (such as when you use docker-compose), they will be defined in an .env file. In .env files, variables are defined in key-value pairs, such as:
VARIABLE1_NAME=some value
VARIABLE2_NAME=another value
You can add as many key-value pairs as needed to the .env file. When you place your container with Docker-Compose, it will read the .env file and apply key-value pairs as needed.
With Portiner, it is managed in a powerful web-based GUI, so there is no need to manually create an .env file.
I want to show you how to use the environment variable feature in Portainer.
What you will need
All you need to do this is a running example of a portiner, which can be easily installed with the help of a docker.
That’s it. Let’s get our environment variable.
How to create a container with environment variables
Let’s use MySQL as an example of assigning environment variables. Log in to Portener and click on Containers in the left navigation. Results page (Figure A), Click Add Container.
Figure A
In a container creation window (Figure B), Give the container a name and then type mysql In the image field.
Figure B
Then, scroll down and click on the Env tab. Here, click Add an environmentally variable (Figure C)
Figure C
For our first environment variable, we are going to set the root password with the MYSQL_ROOT_PASSWORD key and set the value to a strong / unique password. Again, click Add an Environmental Variable and set the MYSQL_DATABASE key to give the database a name (e.g. trtestdb) with a value. Add another environment variable with the MYSQL_USER key. Set this value to something like trtestuser. Finally, add another environment variable with a MYSQL_PASSWORD key and a value with a different strong / unique password.
The complete list of key-value pairs should look something like this Figure D.
Figure D
Once you have filled in the key-value pairs, scroll back up and click to place the container. The installation should happen fairly quickly, and you’ll end up with a running example of MySQL assigning all your custom environment variables. If you click on that container, you can scroll down and see the completeness of the variables listed (Figure e)
Figure e
And this is how docker developers apply environmental variables from within Portiner’s web-based GUI.
Subscribe to TechRepublic How to do tech work on youtube From Jack Wallen to business professionals for all the latest technology advice.
Source link
