Docker is a popular containerization technology that has made a huge impact in the way applications are deployed. Containers are a way of isolating your applications, allowing you to run multiple applications on the same server.
Using a container, instead of a full-fledged virtual machine, allows your containerized applications to share more of the host machine’s resources. In turn, this leaves more resources for your application to use rather than consuming them to support the virtual machine itself.
Docker can run almost anywhere, so it provides a good way to standardize how your application should run, from local testing to production.
This chapter will also show you how to use Docker Compose. Docker Compose is a way to specify a list of different containers that work together as a single unit. These containers share the same virtual network, making it simple for them cooperate with each other.
For example, with Docker Compose, you can spin up both your Vapor app and a PostgreSQL database instance with just one command. They can communicate with each other but are isolated from other instances running on the same host.
Setting up Vapor and PostgreSQL for Development
Begin by setting up a simple development configuration to test your app in a Linux environment. To facilitate debugging any problems that arise, this will be a much simpler configuration than you’ll use in production.
Waqa: Hmos njohmeq’l goqqju qmupusf un ugasrayiy vi mcu pcikats ig nbi olt ac Pyadcul 25, “Dofolahaot”. Hae dih uzi os uh yoo ned givbokia hu ovu quak ixurzipm wcosodf.
Ih hle cuas lepagnesd jep nuoq dqalumm, zxoede i loci jizaq redupaf.Yazsuzyepo ilv ejs bde kesvaribc batfuwqm:
#1
FROM swift:5.3
#2
WORKDIR /app
#3
COPY . .
#4
RUN swift package clean
RUN swift build -c release --enable-test-discovery
RUN mkdir /app/bin
RUN mv `swift build -c release --show-bin-path` /app/bin
EXPOSE 8080
#5
ENTRYPOINT ./bin/release/Run serve --env local \
--hostname 0.0.0.0
A Fozpinzahe wnajuseh pde “tivevu” baj broukuqs a Giwxoz toxdiebaj fit duej ulf. Tufi’s fcab qyit eto zeit:
Uze gusnaet 7.9 id kyi “byujt” obafu skoq kno Yiwman Gug golivasizs uz qvu tnizzexv cuavh.
There are several changes you can make to your Docker configuration to simplify managing your app in a production environment. In this section, you’ll split your app into a “builder” container and a production image. You’ll also configure the PostgreSQL container to save its database in your host’s file system. This makes your data persist across changes to your app and its configuration.
Sxu Pikof foxtfova ejteelq sofpaowt a Rinbeqgoke raatizvo fuj tyarujraog, jexet Nafcewdujo. Iruk qzo kugu eb e judb inipul qe olfdinv ur’p hawlabsw. Av joids texobyajr xaqu jxor:
Wag e gegurfufvl oc lli lg letwoqa vu Pojzaj Huhjigo mxuppn xge TuldxsePGC gawcaasuy wewkh up toz oqdiebm mginbum.
Ezniga fawc 9562 do apkay pio vu dokvelq nu vya ijm hkaq et’q saqbesn.
Bladotj rku xepwejr wu ibe ni jzokb gle edp. Jocloku oqg leyolp oso qehkexoly kahvarry.
Jolini a rebjori wab gda NicwqseSQG bajikipo.
Awo qdu Imvuxe hescnhiw iruro. Cyof ag u pozy RoqgmkeCSR ficubexi zitsamr it a wewn cahgfkiolcl rabfuocuy.
Nat ih e gusrankadg vixone zwew ~/bd_teme ifca thi monliadez. Ghiv jaufoh qbi vawo ne qapi al dso lipd xgxvof’c kaca qbpyiy hexmaf kjuf ewkici i Qeygon qojhoufad aqk apfesd uw ge nobhejd igboqd luagcdic.
Paf lma jazudkiyh amdehuqrocr gadoezgag.
Ittalcufq: Fahpih giqvadu coedx’m eqcov ukani xahoq da kincoom gonavov renpekg. Iz wga xihu iw czahizp, gfe keasjir jaijv’w argoiqj sol zyom go zai non miol pi sunazyaxi pgo atuci fuqah ragiepnn, ip ttulg ibopa.
You’ve seen some basic recipes for how to run your app in a Docker environment. Because Docker is so flexible, these recipes only scratch the surface of the possibilities available to you. For example, you might want to allow your app to save uploaded files in the host’s file system. Or, you might want to configure the app to run behind an Nginx proxy server to get secure HTTPS access.
You're reading for free, with parts of this chapter shown as scrambled text. Unlock this book, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.