Managing environment variables for different environments, such as production and development, is crucial for deploying applications effectively. In this post, I’ll demonstrate how to use Docker Compose with .env
files to easily switch between these environments, using the example of setting a DEBUG_LEVEL
variable to control application logging.
To start, you’ll need different .env
files for each environment:
1. .env
(Common configuration)
ENVIRONMENT=prod
UBUNTU_VERSION=24.04
This common .env
file sets the default ENVIRONMENT
to prod
(production) and specifies the Ubuntu version. These variables are used across all environments.
2. .env.prod
(Production-specific configuration)
DEBUG_LEVEL=ERROR
In the production environment, DEBUG_LEVEL
is set to ERROR
to minimize logging output and avoid exposing sensitive information.
3. .env.dev
(Development-specific configuration)
DEBUG_LEVEL=DEBUG
In the development environment, DEBUG_LEVEL
is set to DEBUG
to provide detailed logs for troubleshooting and development purposes.
The compose.yaml
file is set up to dynamically load the appropriate environment file based on the ENVIRONMENT
variable, which can be set either in the shell or in the .env
file:
services:
test:
image: ubuntu:${UBUNTU_VERSION}
command: ["sh", "-c", "env"]
env_file:
- .env.${ENVIRONMENT}
This configuration uses the env_file
directive to load the environment-specific file (.env.prod
or .env.dev
) based on the value of the ENVIRONMENT
variable.
If the ENVIRONMENT
variable is set in both the .env
file and the shell, the value set in the shell will take precedence. This is useful for temporarily overriding the environment setting without modifying the .env
file. For example:
Setting the ENVIRONMENT
variable in the shell:
export ENVIRONMENT=dev
If you also have ENVIRONMENT=prod
set in the .env
file, the shell setting will overwrite it, and the development environment settings will be used:
$ docker compose up
[+] Running 2/1
✔ Network tmp_default Created 0.1s
✔ Container tmp-test-1 Created 0.1s
Attaching to test-1
test-1 | DEBUG_LEVEL=DEBUG
test-1 | HOSTNAME=f9002b77bc79
test-1 | HOME=/root
test-1 | PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
test-1 exited with code 0
If you want to use the production settings instead, you can unset the shell variable and rely on the value in the .env
file:
unset ENVIRONMENT
Then, when you run docker compose up
again, the output will reflect the production environment:
$ docker compose up
[+] Running 2/1
✔ Network tmp_default Created 0.1s
✔ Container tmp-test-1 Created 0.1s
Attaching to test-1
test-1 | DEBUG_LEVEL=ERROR
test-1 | HOSTNAME=f9002b77bc79
test-1 | HOME=/root
test-1 | PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
test-1 exited with code 0
By using .env
files and setting the ENVIRONMENT
variable in the shell, you have the flexibility to manage environment variables dynamically. This approach simplifies switching between environments and ensures consistent deployment settings, minimizing the risk of configuration errors and improving application reliability.
26 thoughts on “How to Manage Environment Variables for Production and Development with Docker Compose”
Reading your essay was a true pleasure for me. Even the more difficult subjects are easily understandable because of how you present them. Thank you for taking the time to provide such comprehensive details. For anyone interested in this topic, this is an excellent resource.
This is a well-written and insightful article. Your detailed explanations and practical examples make it easy to understand and apply the concepts. I appreciate the effort you put into providing such thorough information. Thank you for sharing your expertise with us.
What a great post! I learned a lot from it. Reading it was really educational for me. You have a wonderful way with words and have done an excellent job of breaking down the ideas. You have my gratitude for the work that you have done on this article. Without a doubt, it is an excellent tool.
Very good website you have here but I was curious about if you knew of any
discussion boards that cover the same topics talked about Escorts in Islamabad this article?
I’d really like to be a part of online community where I can get opinions from other knowledgeable people that share the
same interest. If you have any recommendations, please let me know.
Thanks a lot!
Greetings from Florida! I’m bored at work so I decided to check out your website on my iphone during lunch break.
I love the info you provide here and can’t wait to take a look when I get home.
I’m amazed at how quick your blog loaded on my mobile
.. I’m not even using WIFI, just 3G .. Anyways, great site!
Hey there would you mind stating which blog platform you’re using?
I’m going to start my own blog in the near future but I’m having a hard time making a decision between BlogEngine/Wordpress/B2evolution and Drupal.
The reason I ask is because your design and style
seems different then most blogs and I’m looking for something unique.
P.S Apologies for getting off-topic but I had to ask!
For en utmerket artikkel! Å lese den var virkelig lærerikt for meg. Du ga ekstremt godt organisert materiale, og dine forklaringer var både klare og korte. Din tid og energi brukt på forskning og skriving av denne artikkelen er sterkt verdsatt. Enhver som er interessert i dette emnet vil uten tvil dra nytte av denne ressursen.
For en flott historie! Jeg er så glad for at du delte den. Dataene du ga var både praktiske og enkle å forstå. Din evne til å forenkle ellers vanskelige ideer er sterkt verdsatt. Enhver som er interessert i å lære mer om dette emnet vil dra stor nytte av å lese dette.
For top-notch IPTV in the UK, check out the best IPTV subscriptions and services available.
Whether you need UK IPTV or British IPTV, these options
offer reliable streaming and a great selection of channels.
Find your ideal IPTV service and enjoy high-quality viewing!
Greetings! I know this is kinda off topic but I was wondering which blog platform are you using for this site?
I’m getting fed up of WordPress because I’ve had problems with hackers and I’m looking at options for another platform.
I would be awesome if you could point me in the direction of
a good platform.
Visit my webpage; cryptocurrency copy trading
What an excellent post! Reading it was really educational for me. You provided extremely well-organized material, and your explanations were both clear and brief. Your time and energy spent on this article’s research and writing are much appreciated. Anyone interested in this topic would surely benefit from this resource.
slot gacor merupakan macam permainan ⅼot online yang dikenali karena
kerap memberinya kemenangan besar serta stabil pada pemain. Dengan Return tо
Player (RTP) tinggi ԁan spesifikasi bonus menarik, slot gacor tawarkan kemungkinan menang yang tambah tinggi ktimbang slot lainnya.
Permainan ini jadi favorite beberapa pemaiun sebab kekuatannya untuk tingkatkan kemungkinan menang, ⅾan siapkan pengalaman main yang sengit serta memberi kepuasan dengan hadiah yan menjanjikan.
sllt gacor yaitu type permainan slot online yang dikeetahui lantaran kerap mmemberi kemenangan besar ԁan konstan pada pemain. Dengan Return to Player (RTP) tinggi serta feature bonus menarik, sloot gacor taarkan kesempatan menang yang tambah lebih tinggi ketimbang slot lainnya.
Permainan ini jadi pujaan sejumlah pemaiin karrena kebolehannya untjk mempertingkat kesempatan menang, ɗan siapkan pengalaman main yang sengit Ԁan mengesankan dengan hadiah yang menarik.
What an excellent post! Reading it was really educational for me. You provided extremely well-organized material, and your explanations were both clear and brief. Your time and energy spent on this article’s research and writing are much appreciated. Anyone interested in this topic would surely benefit from this resource.
If you desire to grow your knowledge just keep visiting this
web site and be updated with the hottest news posted here. https://limarc.org/question/guide-par-la-reparation-du-vitrage-thermos-des-fenetres-22/
We’re a group of volunteers and starting a new scheme
in our community. Your site offered us with valuable
information to work on. You have done an impressive job and our entire community will
be grateful to you. https://wiki.team-Glisto.com/index.php?title=Benutzer:RenatoLach7
Excellent piece! Your thorough summary is much appreciated. I now see the issue from a different angle thanks to your insightful comments. You made your points quite clearly with the examples you included. You have my gratitude for penning this.
For en fremragende skrivejobb! Både grundigheten og klarheten i din analyse er sterkt verdsatt. Dine data var både praktiske og relevante. Dette er en artikkel jeg vil komme tilbake til på et senere tidspunkt. Din kunnskap og innsikt er sterkt verdsatt.
I appreciate you taking the time to write and share this insightful piece. It was clear and concise, and I found the data to be really useful. Your time and energy spent on this article’s research and writing are much appreciated. Anyone interested in this topic would surely benefit from this resource.
We stumbled over here by a different page and thought I should check things out.
I like what I see so now i’m following you. Look forward to looking at
your web page yet again.
Look into my blog post Richard
In Cherokee, North Carolina, the demand for legal
cannabis products has grown significantly, with Great Smoky Cannabis playing a key role in providing quality cannabis to the
community. This dispensary offers a range of products, including medical marijuana, recreational cannabis, and CBD
products. Cannabis products are vital in Cherokee due to their health benefits, as well as their contribution to the local economy.
In neighborhoods like Birdtown and Camelot,
residents are turning to legal cannabis for both medicinal and
recreational use, helping enhance their well-being while
supporting local businesses.
Great Smoky Cannabis is located in Cherokee, North Carolina, a town founded in 1839.
Cherokee has a population of 1,604 as of 2022, with 749 households.
It is a small but vibrant town, rich in cultural heritage, as
it is home to the Eastern Band of Cherokee Indians.
The town is accessible via North Carolina Highway 24, which provides
a direct route through the picturesque landscapes of
the Blue Ridge Mountains. Cherokee is well-known for its scenic beauty and its
role as a gateway to the Great Smoky Mountains National
Park, making it a significant destination for visitors.
When purchasing cannabis products in Cherokee, prices vary depending
on the product type. For example, a gram of cannabis flower typically ranges between $10 and $20, while edibles like THC gummies can cost between $20 and $50, depending on the dosage.
Cannabis oils and concentrates are available at higher
prices, starting around $30 for small quantities. Cherokee experiences seasonal temperature changes, with summers averaging
around 80°F and winters dipping to about 30°F. These temperature fluctuations highlight the importance of
temperature-controlled storage for maintaining the quality
of cannabis products.
Cherokee is filled with points of interest that showcase the region’s natural beauty and cultural significance.
The Blue Ridge Parkway offers stunning views of the mountains, winding through scenic overlooks like Ballhoot Scar Overlook
and Big Witch Overlook. Chasteen Creek Cascade is a picturesque waterfall that draws nature enthusiasts year-round.
Fire Mountain Trails – Bike Trail Head offers excellent biking opportunities for outdoor adventurers.
The Cherokee Bear Zoo provides a unique opportunity to observe the native black bears up close, while the Cherokee Welcome Center
serves as a hub for tourists seeking to explore the rich history
and culture of the region. Each of these attractions highlights the
charm and allure of Cherokee, making it a must-visit destination for both locals and tourists.
Choosing Great Smoky Cannabis for your cannabis needs in Cherokee is the best decision for locals and visitors alike.
The dispensary offers a wide selection of high-quality cannabis strains, oils, and edibles, ensuring
that customers find the perfect product for their needs.
With a commitment to customer satisfaction, Great
Smoky Cannabis provides expert guidance on choosing the right cannabis products, whether for medical
or recreational use. As Cherokee continues to grow as a hub for cannabis culture in North Carolina, Great Smoky Cannabis is dedicated
to providing the highest level of service to ensure
a positive experience for everyone in the community.
In Cherokee, North Carolina, cannabis has become an essential part of
the local economy and community well-being. Great
Smoky Cannabis offers a diverse selection of cannabis products,
from medical marijuana to THC edibles, serving the needs of Cherokee residents and visitors alike.
The legalization of cannabis has positively impacted Cherokee, creating job opportunities and offering health benefits to residents in areas like Cherokee
Indian Reservation and Cherokee Gap. With its wide range of products, Great Smoky Cannabis is leading
the way in providing safe, legal access to cannabis.
Great Smoky Cannabis is located in Cherokee, a town founded in 1839.
The town has a population of 1,604, with 749 households, making it a small yet
culturally rich community. Cherokee is known for
being home to the Eastern Band of Cherokee Indians, a
Native American tribe with deep roots in the region. North Carolina Highway 24
runs through Cherokee, providing easy access
to the town’s attractions and connecting it to nearby cities.
Cherokee’s historical significance and scenic beauty make
it a unique place to live and visit, offering a blend of cultural heritage and natural landscapes.
Cannabis products in Cherokee can range in price depending on the type of product
and dosage. For instance, cannabis flower typically costs
around $10 to $20 per gram, while cannabis oils and concentrates can range from $30 to $100
or more, depending on quality and potency. The region experiences a wide range of
temperatures, from summer highs of around 80°F to winter lows of 30°F.
These fluctuations make it crucial for customers to store
cannabis products properly to maintain their freshness and
effectiveness. Great Smoky Cannabis provides guidance on product storage, ensuring that customers get the best results from their purchases.
Cherokee boasts numerous points of interest that attract visitors from all over.
The Blue Ridge Parkway offers breathtaking mountain views, with overlooks like Ballhoot Scar
and Big Witch providing stunning photo opportunities.
The Chasteen Creek Cascade is a beautiful waterfall that’s perfect for a day hike, while the Fire Mountain Trails offer some of
the best mountain biking in the region. The Cherokee Bear Zoo allows visitors to observe and
learn about the native black bears that roam the Smoky Mountains.
Finally, the Cherokee Welcome Center provides valuable information on local history
and attractions, making it a great starting point
for exploring the area. Each of these locations adds to the unique charm
of Cherokee, making it a destination worth visiting.
For those seeking quality cannabis products in Cherokee, Great Smoky Cannabis is
the top choice. This dispensary offers an extensive selection of cannabis strains,
concentrates, and edibles, catering to both medical and recreational users.
With a strong focus on customer service, Great Smoky Cannabis ensures that every customer leaves with the right product for their needs.
Whether you’re a local resident or just visiting Cherokee, Great Smoky Cannabis is dedicated to providing
top-quality cannabis products and an exceptional shopping experience.
The dispensary’s commitment to quality
and service makes it a trusted source for all cannabis needs in the region.
In Cherokee, North Carolina, cannabis is gaining popularity as both a medical and recreational product, thanks
to dispensaries like Great Smoky Cannabis. Offering a range of cannabis products, including CBD oils, THC edibles, and cannabis flower, this
dispensary serves the local community, providing high-quality options to suit various needs.
Residents in neighborhoods like Albemarle and Andrews are
turning to cannabis not only for relaxation but also for its
therapeutic benefits, making Great Smoky Cannabis a vital resource in the area.
Great Smoky Cannabis is based in Cherokee, a town established in 1839.
Cherokee is a small community with a population of 1,604 and 749 households.
This picturesque town, located in the heart of
the Blue Ridge Mountains, is accessible by North Carolina Highway 24, a key route for
residents and visitors alike. Cherokee is best known for being home to the Eastern Band of Cherokee
Indians and its proximity to the Great Smoky Mountains National Park,
one of the most visited national parks in the United States.
The cost of cannabis products in Cherokee can vary
based on the type of product and its potency.
For instance, cannabis flower is priced at around $10 to $20 per gram, while THC edibles and cannabis concentrates can range from $20 to $100.
Cherokee experiences diverse weather conditions, with summer temperatures averaging around 80°F and winter temperatures dropping to about 30°F.
These weather variations make it important to store cannabis products properly to maintain their quality.
Great Smoky Cannabis offers helpful advice on how to
store products to preserve their potency and effectiveness.
Cherokee is filled with captivating points of interest that
showcase its rich natural beauty and cultural
history. The Blue Ridge Parkway is a popular destination for scenic drives, offering
stunning views at stops like Ballhoot Scar Overlook and
Big Witch Overlook. The Chasteen Creek Cascade is a beautiful waterfall, providing a serene escape for
nature lovers. The Fire Mountain Trails are perfect for those
who enjoy mountain biking, offering miles
of well-maintained trails through the forest.
The Cherokee Bear Zoo provides visitors with an up-close
look at the local black bears, while the Cherokee Welcome Center offers a comprehensive guide to the town’s
attractions and history. Each of these sites adds to the charm and allure of Cherokee, making it a must-visit destination.
Great Smoky Cannabis is the go-to choice for cannabis enthusiasts
in Cherokee. Offering a wide variety of products, from cannabis vape pens to topicals, the dispensary caters to
both seasoned users and those new to cannabis. With knowledgeable
staff and a focus on customer satisfaction, Great Smoky Cannabis helps guide customers to the right products for
their individual needs. Whether you’re a local or
just passing through, choosing Great Smoky Cannabis ensures that
you receive the best cannabis products in a welcoming
and professional environment. The dispensary’s dedication to quality and service
makes it a standout in the Cherokee community.
Cannabis is becoming an integral part of life in Cherokee, North Carolina, and Great
Smoky Cannabis is at the forefront of this movement.
Offering a variety of cannabis products, from medical marijuana to recreational cannabis,
Great Smoky Cannabis serves the needs of
the community, providing high-quality options that cater to a wide range of preferences.
In neighborhoods like Beaumont and Blue Ridge Mountains,
residents are discovering the benefits of cannabis for both health and relaxation, contributing to
the growing acceptance and demand for legal cannabis products.
Located in Cherokee, North Carolina, Great Smoky Cannabis is situated in a town founded in 1839.
With a population of 1,604 and 749 households, Cherokee is
a small but culturally significant community.
North Carolina Highway 24 runs through the town, providing easy access
to its many attractions. Cherokee is well-known for its
scenic location in the Blue Ridge Mountains and its role as a cultural center for the Eastern Band of Cherokee
Indians. The town’s history and natural beauty make it an ideal location for both residents and visitors seeking a peaceful yet vibrant community.
Denne artikkelen har gitt meg en rik mengde informasjon. Din grundighet i å skissere hovedideene og illustrere dem med eksempler er virkelig verdsatt. Takket være dette har jeg nå en mye bedre forståelse av emnet. Din inkludering av koblinger til andre nettsteder for videre lesning var også svært nyttig. For de som er nysgjerrige på dette emnet, er dette en utmerket ressurs.
I think everything published made a bunch of sense. However, consider this, suppose you added a little content?
I mean, I don’t want to tell you how to run your website, however suppose you added
a post title that makes people desire more?
I mean How to Manage Environment Variables for Production and Development with Docker Compose
– oriolrius.cat is kinda vanilla. You should
look at Yahoo’s front page and note how they write news headlines to get
viewers interested. You might try adding a video or a pic or two to grab readers excited about what you’ve written. In my opinion, it would make your posts a little bit more interesting.
Do you have a spam problem on this site; I also am a blogger, and I was curious about your situation; many
of us have developed some nice practices and we are looking
to exchange strategies with others, why not shoot me
an e-mail if interested.
This piece of writing is truly a pleasant one it assists
new internet users, who are wishing in favor of blogging.
There’s definately a great deal to find out about this subject.
I love all the points you have made.
Comments are closed.