27.5 C
New York
Monday, July 25, 2022

Buy now

How to combine environmental variables in a container with a portainer

Facebook
Twitter
Pinterest
WhatsApp

Jack Wallen shows you how easy it is to use environmental variables in your container with the Portener Management Platform.

In shipping containers
Photo: iStockphoto / wissanu01

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

My pot list grows every day.
My pot list grows every day.

In a container creation window (Figure B), Give the container a name and then type mysql In the image field.

Figure B

A new MySQL container is being created at Portener.
A new MySQL container is being created at Portener.

Then, scroll down and click on the Env tab. Here, click Add an environmentally variable (Figure C)

Figure C

The Environment Variables tab on the Container Creation page.
Variable tab of the environment on the container creation page.

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

Our environment is ready to go to the list of variable key-value pairs.
Our environment is ready to go to the list of variable key-value pairs.

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

Here you can also see some of the environment variables that we have set with the container image.
Here you can also see some of the environment variables that we have set with the container image.

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

Facebook
Twitter
Pinterest
WhatsApp
Previous article“Liberal world order” is under serious attack, disinformation is growing in the United States, says Joe Biden
Next articleAlia Bhatt and Ranveer Singh will be the first guests at Koffee with Karan 7: Report

Related Articles

Shamshera BO Collection Day 1: ‘Shamshera’ earned less than the first day’s ‘Prithviraj’, only collected 10 crore

True caller is not necessary!  Without an app you know who is calling you

Backstage news on Vince McMahon’s retirement, Stephanie McMahon and Nick Khan’s new WWE roles, more

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Stay Connected

0FansLike
3,411FollowersFollow
0SubscribersSubscribe

Latest Articles

Shamshera BO Collection Day 1: ‘Shamshera’ earned less than the first day’s ‘Prithviraj’, only collected 10 crore

True caller is not necessary!  Without an app you know who is calling you

Backstage news on Vince McMahon’s retirement, Stephanie McMahon and Nick Khan’s new WWE roles, more

Top news from the world of technology this week

Sports

Divyenndu Aka ‘Munna Bhaiya’ Gives Classic Response to Rishabh Pant’s ‘Mirzapur’ Tweet